dmikester1 Posted March 1, 2013 Share Posted March 1, 2013 I'm having some troubles with this one. I set up my array like so: $POs[] = array( $jobID=>array( 'FSME' => $matTotal, 'FSMC' => $matTotal, 'FSDE' => $draftingTotal, ... And say $jobID is equal to 312. Now I am trying to access one of those values. I tried: $POs[$jobID]['FSME'] with $jobID being 312. Then I get "Notice: Undefined offset: 312 in..." Any ideas how I can access this variable? Thanks Mike Quote Link to comment https://forums.phpfreaks.com/topic/275088-accessing-a-value-in-a-multidimensional-associative-array/ Share on other sites More sharing options...
Solution jcbones Posted March 1, 2013 Solution Share Posted March 1, 2013 You need to change it to: $POs[$jobID] = array('FSME' => $matTotal, ...); Or access it using: $POs[0][312]['FSMC']; Quote Link to comment https://forums.phpfreaks.com/topic/275088-accessing-a-value-in-a-multidimensional-associative-array/#findComment-1415830 Share on other sites More sharing options...
Barand Posted March 1, 2013 Share Posted March 1, 2013 try echo '<pre>', print_r($POs, 1), '</pre>'; so you can see what is in the array Quote Link to comment https://forums.phpfreaks.com/topic/275088-accessing-a-value-in-a-multidimensional-associative-array/#findComment-1415831 Share on other sites More sharing options...
dmikester1 Posted March 1, 2013 Author Share Posted March 1, 2013 You need to change it to: $POs[$jobID] = array('FSME' => $matTotal, ...); Or access it using: $POs[0][312]['FSMC']; Thank you. I changed the way I was inserting in the array. I knew there had to be an easier way than what I was doing, but was having a brain fart or something. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/275088-accessing-a-value-in-a-multidimensional-associative-array/#findComment-1415833 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.