Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 反转串联语句中的变量,反转未解释的输出_Php_Syntax_Logic - Fatal编程技术网

Php 反转串联语句中的变量,反转未解释的输出

Php 反转串联语句中的变量,反转未解释的输出,php,syntax,logic,Php,Syntax,Logic,这对我来说完全是个谜。我有一个简单的脚本,可以输出数组中的数字。下面是它的外观: <?php $numbers = array(1,2,3,4); $total = count($numbers); $sum = 0; $i = 0; foreach($numbers as $count) { $i = $i++; if ($i < $total) { $output = $out

这对我来说完全是个谜。我有一个简单的脚本,可以输出数组中的数字。下面是它的外观:

<?php
    $numbers = array(1,2,3,4);
    $total = count($numbers);
    $sum = 0;  

    $i = 0;
    foreach($numbers as $count) {
        $i = $i++;

        if ($i < $total) {
            $output = $output . $count;
        }
    }
    echo $output;
?>
数字颠倒了!(4,3,2,1)这背后的逻辑是什么?就是这样吗?我不能相信这是一个武断的规则,因为它确实存在

代码中有人有解释吗?

$output = $output . $count
 $output = $count.$output;
您正在将$count中的值连接到$output变量,从而创建一个字符串。因此,在每次迭代中,您都会将新值添加到字符串的末尾

当你反转代码时

$output = $output . $count
 $output = $count.$output;

您正在将新值放在实际字符串之前,以便以相反的方式获得上一个字符串,就像。。。真的?你知道
做什么吗?用笔和纸一定要遵循这一点。慢慢来。我以前从未使用过PHP,但是,看看代码就可以回答您的问题。