darth_tater Posted January 7, 2011 Share Posted January 7, 2011 Hey all. another quick question. here is the output of my 2D array: array(2) { ["folder.jpg"]=> array(2) { ["valid"]=> bool(true) ["error"]=> bool(false) } ["file.mp3"]=> array(2) { ["valid"]=> bool(true) ["error"]=> bool(false) } } how can i foreach my way into getting an iterator that points to the folder.jpg and file.mp3? as is now, i have something that looks like this: foreach($arr as $val){ var_dump($val) } the var_dump of $val is an *array*. Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/223629-foreach-to-access-specific-spot-in-a-2d-array/ Share on other sites More sharing options...
sooner Posted January 7, 2011 Share Posted January 7, 2011 again do a foreach inside that foreach... Link to comment https://forums.phpfreaks.com/topic/223629-foreach-to-access-specific-spot-in-a-2d-array/#findComment-1155986 Share on other sites More sharing options...
darth_tater Posted January 7, 2011 Author Share Posted January 7, 2011 That gets me access to the 2nd dimension arrays. I dont need / want that. each array is built like this: array(2) { ["folder.jpg"]=> array(2) { ["valid"]=> bool(true) ["error"]=> bool(false) } ["file.mp3"]=> array(2) { ["valid"]=> bool(true) ["error"]=> bool(false) } } I need access to the folder.jpg and file.mp3, the first and second elements in the array. the foreach i have now should work but it returns the secondary array (which i dont need) not the string that is the first and second element in the 1st dimension Link to comment https://forums.phpfreaks.com/topic/223629-foreach-to-access-specific-spot-in-a-2d-array/#findComment-1155987 Share on other sites More sharing options...
darth_tater Posted January 7, 2011 Author Share Posted January 7, 2011 Woo! i was playing around a bit more when it suddenly occurred to me! I wasn't giving PHP a reason to separate out the two! here is what i have now (and it works!) foreach($this->validArray as $key => $val ){ echo("<br><br> trying vdump of KEYs<br><br>"); var_dump($key); } before i did not have the => $val. Including it tells PHP that i want to seperate the KEY (the file name!) from the value (the sub-dimensional array) Problem solved! - thread marked as such! Link to comment https://forums.phpfreaks.com/topic/223629-foreach-to-access-specific-spot-in-a-2d-array/#findComment-1155995 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.