Array_key_exists () function usage problems

Source: Internet
Author: User
Array_key_exists () function usage problem $ res Array, use print_r ($ res); statement output: Array & nbsp; (& nbsp; [0] & nbsp; & gt; & nbsp; Array & nbsp; (& nbsp; [tagname] & nbsp; & gt; & nbsp; KF_FIC01341.TOTALIZERA_2.PV & nbsp; [units] & array_key_exists () function usage problems
$ Res array, using print_r ($ res); after the statement is 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?
------ Solution --------------------
Array_key_exists ("value", $ res [0])
------ Solution --------------------
$ 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 "this key value does not exist "."
";
}
}
Array_walk ($ arr, 'Check _ INDEX ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.