如何以正确的方式从for循环输出结果

时间:2017-07-08 19:24:28

标签: php loops for-loop

我正在尝试从for循环输出结果。它没有正确的输出方式。我已将结果粘贴到代码的末尾。它不应该像这样回应。

for ($i = 0; $i < count($_FILES); $i++) {
      $target_path = $_FILES[$i];

        if($i == 0 ){
        $test1 = $target_path;  
        }

        if($i == 1 ){
        $test2 = $target_path;
        } 

//This part should output only 2 results but it outputs something different.
        echo $test1." img 1 <br>";  

        echo $test2." img 2 <br>";
    }

它不应该输出以下内容:

73c4d636e78bc7d33f90c182fc6ffaec.png img 1
img 2
73c4d636e78bc7d33f90c182fc6ffaec.png img 1
5eeb5c30fc9bba82e057953945b06eab.jpg img 2 

2 个答案:

答案 0 :(得分:1)

这应该有效。

AsNoTracking

或者:

process

或者:

for i in queryset:
    print(json.loads(json.dumps(str(i)))) 

答案 1 :(得分:0)

就这样做

  $target_path_arr = array();
  for ($i = 0; $i < count($_FILES); $i++) {
    $target_path = $_FILES[$i];
    $target_path_arr[] = $target_path; // use this in future
    echo $target_path." img ". $i+1."<br>";
 }