phpSensei Posted July 9, 2010 Share Posted July 9, 2010 Hello... Code is Self explainatory, is the following possible to do? Script: $arr = array(); array_push($arr, $something => "sdasd"); I keep getting an error Parse error: parse error in C:\wamp\www\uLoad\index.php on line 29 Link to comment https://forums.phpfreaks.com/topic/207201-array_push/ Share on other sites More sharing options...
phpSensei Posted July 9, 2010 Author Share Posted July 9, 2010 Ah solved nvm Link to comment https://forums.phpfreaks.com/topic/207201-array_push/#findComment-1083338 Share on other sites More sharing options...
joel24 Posted July 9, 2010 Share Posted July 9, 2010 are you trying to add another value to the array, or create a double array?! this will work, adding "sdasd" as a value in the array. $arr = array(); array_push($arr, "sdasd"); Link to comment https://forums.phpfreaks.com/topic/207201-array_push/#findComment-1083340 Share on other sites More sharing options...
AbraCadaver Posted July 9, 2010 Share Posted July 9, 2010 So obviously its not possible. The second parameter needs to be a string, array, object, etc. not a construct that only applies to array definition or foreach expression. Just use the normal: $arr[$something] = "sdasd"; Link to comment https://forums.phpfreaks.com/topic/207201-array_push/#findComment-1083343 Share on other sites More sharing options...
phpSensei Posted July 9, 2010 Author Share Posted July 9, 2010 $arr[] = array("sdfdf"=>"sdfsd"); its the only way.. Link to comment https://forums.phpfreaks.com/topic/207201-array_push/#findComment-1083354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.