Array_keys () B function?

Source: Internet
Author: User
Array_keys () B function? Http://docs.php.net/manual/zh/function.array-keys.php

 "aa","2"=>"bb","3"=>"cc","4"=>"bb");   $y1=array_keys($x,bb,false);   $y2=array_keys($x,bb,true);   print_r($x);   print_r($y1);   print_r($y2);?>




What is the role of the 3rd function parameters?
Why did the program go wrong?




Reply to discussion (solution)

Please refer to the following link for more information: http://baike.baidu.com/view/4068562.htm.

Change it to $ y2 = array_keys ($ x, "bb", true );

Why did the program go wrong?
Because bb is not a constant, and you do not enclose it in quotation marks.
The third parameter specifies whether to check the data type

Strict

Determine whether to use strict comparison (=) during search ).

The error is caused by $ y1 = array_keys ($ x, bb, false). bb is not enclosed in quotation marks. php first considers it a constant, and your code does not have a constant, so an error is reported.

The third parameter is to return the key name with the specified value based on the type,
$ X = array ("1" => "111111", "2" => "bb", "3" => "cc ", "4" => "bb ");
$ Y1 = array_keys ($ x, 111111, true); // no data will be returned (in the original number Group, "111111" is a string type, and here it is a number type)

The error message is that the string must be enclosed in single or double quotation marks.
$ Y1 = array_keys ($ x, "bb", false );
$ Y2 = array_keys ($ x, "bb", true );

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.