yazzou Posted October 12, 2012 Share Posted October 12, 2012 (edited) 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)] Edited October 12, 2012 by yazzou Quote Link to comment https://forums.phpfreaks.com/topic/269387-verify-if-a-key-has-a-value-in-subarray/ Share on other sites More sharing options...
kicken Posted October 12, 2012 Share Posted October 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269387-verify-if-a-key-has-a-value-in-subarray/#findComment-1384764 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.