Array_key_exists () function usage problem $ res array, use print_r ($ res); after the statement output:
Array ([0] => Array ([tagname] => KF_FIC01341.TOTALIZERA_2.PV [units] => KNm3 [value] => 0) [1] => Array ([tagname] => KF_FIC01342.TOTALIZERA_4.PV [units] => KNm3 [value] => 0 ))
False is returned when the array_key_exists ("value", $ res); statement is used. I checked the cause carefully. The $ res array is a multi-dimensional array with two key names: 0 and 1. no value exists. Therefore, false is returned.
How can we determine whether the $ res array has a value key? How to write code for multi-dimensional arrays?
Reply to discussion (solution)
Array_key_exists ("value", $ res [0])
$ Arr = Array ('0' => Array ('tagname' => 'kf _ FIC01341.TOTALIZERA _ 2. PV ', 'units' => 'knm3', 'value' => 0), '1' => Array ('tagname' => 'kf _ FIC01342.TOTALIZERA _ 4. PV ', 'units' => 'knm3', 'value' => 0); function check_index ($ item, $ key) {if (array_key_exists ("value ", $ item) {echo "this key value exists "."
";} Else {echo" no such key value "."
";}} Array_walk ($ arr, 'Check _ INDEX ');
$ Arr = array (0 => array ('tagname' => 'kf _ FIC01341.TOTALIZERA _ 2. PV ', 'units' => 'knm3', 'value' => 0), 1 => array ('tagname' => 'kf _ FIC01342.TOTALIZERA _ 4. PV ', 'units' => 'knm3', 'value' => 0); function my () {$ arr = func_get_args (); foreach ($ arr as $ k =>$ v) {$ item = array_key_exists ('value', $ v); if ($ item) {echo 'Exists'; break ;} else {'Nonexistent ';}} call_user_func_array ('my', $ arr );
The moderator method is the easiest. thank you ~~