Jump to content

ForEach to access specific spot in a 2d array


darth_tater

Recommended Posts

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!

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

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.