开发者

Cannot use a scalar value as an array

开发者 https://www.devze.com 2023-04-11 02:43 出处:网络
I am trying this code: for ($x = 0; $x < $num开发者_如何学编程Col; $x++) { for ($i = 0; $i < $numRows; $i++) {

I am trying this code:

for ($x = 0; $x < $num开发者_如何学编程Col; $x++) {
    for ($i = 0; $i < $numRows; $i++) {
        $arr.$x[] = $todas[$i][$x]."\n"; //problem here
    }
}

echo $arr0[0];
echo $arr1[0];
...

But i get this warning: Cannot use a scalar value as an array

and the echos do nothing. Why ? and what is the solution ?


Here's what you think you want to do. Replace your //problem here line with:

${'arr' . $x}[] = $todas[$x][$i]."\n";

But I would strongly recommend against doing that. Just use your bidimensional array.


I think you meant: ${'arr'.$x}[] instead of $arr.$x[].

 $arr.$x[]

Will concatenate the string representation of $arr and $x together so you end up with something like 'Array0'[] = ... instead of $arr0[]


When you write $arr.$x[], it is equal to $arr[$x][]

Try replacing your echos by

echo $arr[0][0];
echo $arr[1][0];
0

精彩评论

暂无评论...
验证码 换一张
取 消