lj11 Posted August 7, 2008 Share Posted August 7, 2008 I am trying to add a value to $cells[r2] array: <?php $cells=array("r1=>array("A","B"), "r2"=>array(1, 2, 3, 4)); print_r (cells['r2']); $cells['r2'][]=5; \\ <---- THIS IS WHATS WRONG?? print_r (cells['r2']); ?> I run this, but always get: Array ( [r1] => Array ( [0] => A [1] => B ) [r2] => [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) Warning: Cannot use a scalar value as an array in ... on line 3 Array ( [r1] => Array ( [0] => A [1] => B ) [r2] => [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) plz help ??? Link to comment https://forums.phpfreaks.com/topic/118702-solved-keep-getting-cannot-use-a-scalar-value-as-an-array/ Share on other sites More sharing options...
trq Posted August 7, 2008 Share Posted August 7, 2008 Can you post your actual code? The code you have provided will throw syntax errors before any others. Link to comment https://forums.phpfreaks.com/topic/118702-solved-keep-getting-cannot-use-a-scalar-value-as-an-array/#findComment-611162 Share on other sites More sharing options...
lj11 Posted August 7, 2008 Author Share Posted August 7, 2008 sorry, yeah $cells=array("r4"=>array(1,2,3,4,5,"pie"),"r5"=>5); $row=5; $type="r"; $rownum=$type.$row; print_r ($cells); $cells[$rownum][] = 7; print_r ($cells); Link to comment https://forums.phpfreaks.com/topic/118702-solved-keep-getting-cannot-use-a-scalar-value-as-an-array/#findComment-611163 Share on other sites More sharing options...
DarkWater Posted August 7, 2008 Share Posted August 7, 2008 r5 isn't an array, it's a string. Make it an array in the initialization. Link to comment https://forums.phpfreaks.com/topic/118702-solved-keep-getting-cannot-use-a-scalar-value-as-an-array/#findComment-611169 Share on other sites More sharing options...
lj11 Posted August 7, 2008 Author Share Posted August 7, 2008 WOWO that was simple, thanks for the help! Link to comment https://forums.phpfreaks.com/topic/118702-solved-keep-getting-cannot-use-a-scalar-value-as-an-array/#findComment-611170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.