Jump to content

Verify If A Key Has A Value In Subarray


yazzou

Recommended Posts

Hello

 

I have the following array and i would like to make a function where i can check if one of the [tid] values is equal to 2 or not. How can do that in such multidimensional array ?

 

[/background][/size][/font][/color]

Array
(
[0] => Array
(
[tid] => 2
[taxonomy_term] => stdClass Object
(
[tid] => 2
[vid] => 2
[name] => languedoc
[description] => 
[format] => 
[weight] => 0
[vocabulary_machine_name] => mots_cles
[rdf_mapping] => Array
(
[rdftype] => Array
(
[0] => skos:Concept
)

[name] => Array
(
[predicates] => Array
(
[0] => rdfs:label
[1] => skos:prefLabel
)

)

[description] => Array
(
[predicates] => Array
(
[0] => skos:definition
)

)

[vid] => Array
(
[predicates] => Array
(
[0] => skos:inScheme
)

[type] => rel
)

[parent] => Array
(
[predicates] => Array
(
[0] => skos:broader
)

[type] => rel
)

)

)

)

[1] => Array
(
[tid] => 3
[taxonomy_term] => stdClass Object
(
[tid] => 3
[vid] => 2
[name] => marseille
[description] => 
[format] => 
[weight] => 0
[vocabulary_machine_name] => mots_cles
[rdf_mapping] => Array
(
[rdftype] => Array
(
[0] => skos:Concept
)

[name] => Array
(
[predicates] => Array
(
[0] => rdfs:label
[1] => skos:prefLabel
)

)

[description] => Array
(
[predicates] => Array
(
[0] => skos:definition
)

)

[vid] => Array
(
[predicates] => Array
(
[0] => skos:inScheme
)

[type] => rel
)

[parent] => Array
(
[predicates] => Array
(
[0] => skos:broader
)

[type] => rel
)

)

)

)

) 
[color=#000000][font=verdana][size=1][background=rgb(252, 252, 252)]
Link to comment
https://forums.phpfreaks.com/topic/269387-verify-if-a-key-has-a-value-in-subarray/
Share on other sites

Set a flag variable to false, then use a foreach loop to go over each array element and check it's ['tid'] element to see if it matches. If it does, set the flag variable to true. After the loop, check if the flag variable is true or false.

 

 

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.