PHP: Find Keys / Values in a Multidimensional Array. Help!

Associate
Joined
9 Nov 2005
Posts
767
Location
places..
Hello,

<noob>

Hi I'm using an API that returns JSON. I have converted the return JSON using "json_decode", into a multidimensional array.

I need to find the number of a certain key with a specified Value (in this case bool = true). I don't seem to be able to find any functions to do this.

In a nutshell each of the child arrays is a re-iteration of the same array, I just need to find how many (child arrays) have a certain key that has a true value, I.E. how many of the child arrays have a true value for the 'foo' key.

I'm sure there is probably a function to do this, or will I have to foreach though and add it up? It's a little frustrating!

Thanks for any help

</noob>
 
Sorry jestar, I know it's not the best explanation. Well it's carp.

Perhaps a little more info would help. I simply need the number of occurrences of a specified key, "foo" being true. The key will be in each of the sub-arrays so to speak.

Each of the arrays contains certain attributes, for a list of objects. Say for example, the array describes a car park, with a sub array for each car, containing information such as make, model, colour date of manufacture etc.

I want to go though and find the number of times there is say, a "red" car. In this case the key is boolean, and I looking for the number of times the key is true.

Is this a better description? I'm no good at coming the lingo :P

Cheers



EDIT: looks like this is what i was after, I've not yet fully read it, but it looks like it foreach'es though the array, which is what i meant by adding up :P
 
Last edited:
Back
Top Bottom