简体   繁体   中英

how can i get the data from this array in php?

I have the following code..

$array_test = array();

for($i = 0;$i<5;$i++) {
    array_push($array_test,array("result".$i=>"exist_data".$i));
}

for($j = 0; $j<count($array_test);$j++) {
    echo $array_test[$j];
}

var_dump($array_test); // the data exist

but the loop for only show me ArrayArrayArrayArray

thanks for help.

echo $array_test[$j]; would not work because you have a 2D array and can't access the variables of 2D array in that way. This would throw Array to String Conversion error.

Change your code to :-

for($j = 0; $j<count($array_test);$j++) {
    echo $array_test[$j]["result".$j] ."<br>";
}

Output

exist_data0
exist_data1
exist_data2
exist_data3
exist_data4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM