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!

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.