whit3fir3 Posted November 29, 2009 Share Posted November 29, 2009 I am having a problem with an array that I am hoping some one can help me out with. I have an associative, multidimensional array. The array has 2 keys named "name" and "value". After the array is created I am using the array_push function to try and append some values to the end of the array and I can not get it to work for me. Any example of the code I am trying is below: $myArray = array("name"=>"SomeValue", "value"=>"AnotherValue"); array_push($myArray["name"], "SomeAddedValue"); array_push($myArray["value"], "AnotherAddedValue"); What happens is I only see the values in the array that the array was created with. I never see the new values and no errors are thrown. Does anyone know of a better way to add values to an associative, multidimensional array. Thanks, whit3fir3 Link to comment https://forums.phpfreaks.com/topic/183269-array-question/ Share on other sites More sharing options...
Alex Posted November 29, 2009 Share Posted November 29, 2009 That is not a multidimensional array. Neither $myArray["name"] nor $myArray["value"] is an array. Edit: Perhaps you meant something like this: $myArray = Array( 'name' => Array("SomeValue"), 'value' => Array("AnotherValue") ); array_push($myArray['name'], 'Added Name'); array_push($myArray['value'], 'Added Value'); echo "<pre>" . print_r($myArray, true) . "</pre>"; Output: Array ( [name] => Array ( [0] => SomeValue [1] => Added Name ) [value] => Array ( [0] => AnotherValue [1] => Added Value ) ) Link to comment https://forums.phpfreaks.com/topic/183269-array-question/#findComment-967282 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.