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 Link to comment https://forums.phpfreaks.com/topic/275088-accessing-a-value-in-a-multidimensional-associative-array/ Share on other sites More sharing options...
jcbones Posted March 1, 2013 Share Posted March 1, 2013 You need to change it to: $POs[$jobID] = array('FSME' => $matTotal, ...); Or access it using: $POs[0][312]['FSMC']; 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 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! 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
Archived
This topic is now archived and is closed to further replies.