php - Get index for multi-dimensional array -
i need index of multidimensional , output variable. know simple struggling it.
for example given following:
[1]=> array(11) { ["field_label"]=> string(24) "what first name?" ["field_name"]=> string(6) "f_name" ["identifier"]=> bool(true) ["options"]=> bool(false) ["form_name"]=> string(12) "demographics" } [2]=> array(11) { ["field_label"]=> string(23) "what last name?" ["field_name"]=> string(6) "l_name" ["identifier"]=> bool(true) ["options"]=> bool(false) ["form_name"]=> string(12) "demographics" } [3]=> array(11) { ["field_label"]=> string(32) "researcher took measurements" ["field_name"]=> string(17) "weight_researcher" ["identifier"]=> bool(false) ["options"]=> bool(false) ["form_name"]=> string(6) "weight" }
i want find index first element has form_name of "weight" (#3)
just use foreach , if inside it:
foreach($array $key => $value) { // ^ here resides key of parent array if($value['form_name'] == 'weight') { // if form name weight echo $key; // echo key break; // stop on first occurence } }
Comments
Post a Comment