php - How can I loop through a two-dimensional array and display the values if another value is true? -


i have array like:

0 name => 'john', age => '99', istheone => boolean true  1 name => 'jeff', age => '88', istheone => boolean false 

what need is, each row in array, display contents if field istheone true.

i thought i'd need use while loop this, i'm bit stuck. don't know how move forward this?

this should work you:

<?php      $array = array(                 0 => array(                     "name" => 'john',                     "age" => '99',                     "istheone" => true                 ),                  1 => array(                     "name" => 'jeff',                     "age" => '88',                     "istheone" => false                 )             );      foreach($array $subarray) {         foreach($subarray $k => $v) {             if($k == "istheone" && $v == true)                 echo "key: " . $k . " value: " . $v;         }     }  ?> 

output:

key: istheone value: 1 

Comments

Popular posts from this blog

java - Unable to make sub reports with Jasper -

sql - The object name contains more than the maximum number of prefixes. The maximum is 2 -

scala - play framework: Modules were resolved with conflicting cross-version suffixes -