next Posted December 3, 2012 Share Posted December 3, 2012 (edited) I populate $data array with this code: foreach($el as $item) $data[] = array($item->name => $item->value); var_dump shows the following inside $data: array(32) { [0]=> array(1) { ["submitted"]=> string(1) "Y" } [1]=> array(1) { ["type"]=> string(5) "labor" } [2]=> array(1) { ["wonum"]=> string(9) "XX-111111" } [3]=> array(1) { ... yet when I want to access wonum element I get an error: Undefined index: wonum in C:\xampp\htdocs\test\test.php on line 94 This is how I'm accessing it: echo $data['wonum']; Why is it not working? Edited December 3, 2012 by next Quote Link to comment https://forums.phpfreaks.com/topic/271553-multidimensional-array-accessing-elements-error/ Share on other sites More sharing options...
next Posted December 3, 2012 Author Share Posted December 3, 2012 Sorry, I should stop doing this. I figured it out. I should have been populating my array like this: $data[$item->name] = $item->value; Quote Link to comment https://forums.phpfreaks.com/topic/271553-multidimensional-array-accessing-elements-error/#findComment-1397287 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.