Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.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_Arrays_Loops_Store - Fatal编程技术网

Php 在多维数组中存储变量?

Php 在多维数组中存储变量?,php,arrays,loops,store,Php,Arrays,Loops,Store,我试图将while循环中设置的变量存储在多维数组中。我想把阵列打印出来 我所做的: $counter = 0; while($counter < 10){ $a = $counter + 10; $b = $counter + 5; $file_ar[] = array($a,$b); $counter++; } /* $file_ar[1-10] = "$a","$b" */ $i = 0; while(isset($file_ar[$i])) {

我试图将while循环中设置的变量存储在多维数组中。我想把阵列打印出来

我所做的:

$counter = 0;
while($counter < 10){
    $a = $counter + 10;
    $b = $counter + 5;
    $file_ar[] = array($a,$b);
    $counter++;
}

/* $file_ar[1-10] = "$a","$b" */

$i = 0;
while(isset($file_ar[$i])) {
    $a = $file_ar[$i][0];
    $b = $file_ar[$i][1];

    echo $a.' is not '.$b;
}
$counter=0;
而($counter<10){
$a=$counter+10;
$b=$counter+5;
$file_ar[]=数组($a,$b);
$counter++;
}
/*$file_ar[1-10]=“a”、“b”*/
$i=0;
而(isset($file_ar[$i])){
$a=$file_ar[$i][0];
$b=$file_ar[$i][1];
echo$a.“不是”。$b;
}
当我运行这段代码时,我不会得到任何东西

这是什么原因


谢谢大家!

这里是代码-

<?php
$counter = 0;
while($counter < 10){
    $a = $counter + 10;
    $b = $counter + 5;
    $file_ar[] = array($a,$b);
    $counter++;
}
/* $file_ar[1-10] = "$a","$b" */

$i = 0;
while(isset($file_ar[$i])) {
    $a = $file_ar[$i][0];
    $b = $file_ar[$i][1];

    echo $a.' is not '.$b;
    $i++;
}

您需要添加要添加到的数组的索引,或者只需在其上写入

$counter = 0;
while($counter < 10){
    $a = $counter + 10;
    $b = $counter + 5;
    $file_ar[$counter] = array($a,$b);
    $counter++;
}

$i = 0;
while(isset($file_ar[$i])) {
    $a = $file_ar[$i][0];
    $b = $file_ar[$i][1];
    if ($a != $b)
        echo $a.' is not '.$b;
    else
        echo $a.'='.$b;
    $i++;
}
$counter=0;
而($counter<10){
$a=$counter+10;
$b=$counter+5;
$file_ar[$counter]=数组($a,$b);
$counter++;
}
$i=0;
而(isset($file_ar[$i])){
$a=$file_ar[$i][0];
$b=$file_ar[$i][1];
如果($a!=$b)
echo$a.“不是”。$b;
其他的
回声$a.'='.$b;
$i++;
}

而(isset($file_ar[$i]){}
可能是问题所在。
var\u dump($file\u ar)
为您提供了什么?您期望的结果是什么?while循环如何结束?