ok Posted December 3, 2008 Share Posted December 3, 2008 what is wrong with this codes? <?php //Testing multi-dimentional array echo "<h3>Multi-Dimentional Array test.</h3>"; echo "<br>"; for($i=0; $i<=10; $i++) { $names[]=$i; } echo "<br>"; echo "<b>Single array</b>"; echo "<br>"; echo "<b>print_r</b>"; echo "<pre>"; print_r($names); echo "</pre>"; echo "<br>"; echo "<b>Multi array</b>"; echo "<br>"; for($i=0; $i<=10; $i++) { $names[$i][$i]=$i; } echo "<b>print_r</b>"; echo "<pre>"; print_r($names); echo "</pre>"; ?> Thank you in advance Link to comment https://forums.phpfreaks.com/topic/135266-array-error-scalar-value/ Share on other sites More sharing options...
xtopolis Posted December 3, 2008 Share Posted December 3, 2008 Second loop, you need to declare that it is an array first. for($i=0; $i<=10; $i++) { $names[$i]=array(); $names[$i][$i]=$i; } Link to comment https://forums.phpfreaks.com/topic/135266-array-error-scalar-value/#findComment-704549 Share on other sites More sharing options...
btherl Posted December 3, 2008 Share Posted December 3, 2008 This is only a problem because you used $names as a 1-level array first, and then used it as a 2-level array. If you use a fresh variable you should not have any problems making the 2-level array. Link to comment https://forums.phpfreaks.com/topic/135266-array-error-scalar-value/#findComment-704559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.