Function parameter: true? This post was last edited by u012362664 at 20:35:48, January 9 ,.
111,2=>12,3=>3333); $y1=in_array(12,$x1,true); echo $y1; echo "\r\n"; $x2=array(1=>111,2=>12,3=>3333); $y2=in_array('12',$x2,true); echo $y2; echo "\r\n"; $x3=array(1=>111,2=>12,3=>3333); $y3=in_array("12",$x3,true); echo $y3; echo "\r\n"; ?>
Program output:
1
0
0
Problem:
1. the above program is compiled without syntax errors.
The in_array () function contains 1st parameters, all of which are int integers.
The in_array () function has 3rd parameters: true. what is the role?
Why, 1st arrays, return result: 1, find.
Returns 0 for every 2 or 3 arrays. cannot be found?
Reply to discussion (solution)
Bool in_array (mixed needle, array haystack [, bool strict])
Search for needle in haystack. If yes, TRUE is returned. otherwise, FALSE is returned.
If the value of the third strict parameter is TRUE, the in_array () function checks whether the needle type is the same as that in haystack.
Bool in_array (mixed needle, array haystack [, bool strict])
Search for needle in haystack. If yes, TRUE is returned. otherwise, FALSE is returned.
If the value of the third strict parameter is TRUE, the in_array () function checks whether the needle type is the same as that in haystack.
1) 12 and 12 have the same content and type. Return value: 1
2) Why are the types of '12' and '12' with the same content?
3) Why is the content of "12" the same as that of "12" and "12" different from that of "12?
Whether the execution process of the in_array () function is like this:
1. check the parameter types of the function.
If the type is incorrect, a syntax error is displayed.
If the type is correct, execute 2
2. search for arrays.
3. if it is found, the returned result is: 1.
If no result is found, the returned result is 0.
The landlord, 12 is a number, '12' and "12" are strings, so the type is different
Function parameter: true, PHP official Chinese document, not very detailed.
My understanding is:
Function in_array ()
1) if no value is set to true, the value after type conversion is used as the 1st parameter and compared with the array element. .
2) if no value is true, the first 1st parameters are used, and the value before the type conversion is used, which is compared with the array element. .
Yes?
Change:
Function parameter: true, PHP official Chinese document, not very detailed.
My understanding is:
Function in_array ()
1) if no value is set to true, the value after type conversion is used as the 1st parameter and compared with the array element. .
2) add true and 1st parameters, use the value before type conversion, and compare it with the array element. .
Yes?
"Aaaa", 2 => 12, 3 => "bb"); $ y1 = in_array (12, $ x1); // type conversion value: 12 echo $ y1; echo "\ r \ n"; $ x2 = array (1 => 111,2 => 3333 =>); $ y2 = in_array ('12', $ x2 ); // type conversion value: 12 echo $ y2; echo "\ r \ n"; $ x3 = array (1 => 111,2 => 3333 => ); $ y3 = in_array ("12", $ x3); // type conversion value: 12 echo $ y3; echo "\ r \ n"; echo "----------------------------";?>
"Aaaa", 2 => 12, 3 => "bb"); $ y1 = in_array (12, $ x1, true); // The value before type conversion: 12 echo $ y1; echo "\ r \ n"; $ x2 = array (1 => 111,2 => 3333 =>); $ y2 = in_array ('12', $ x2, true ); // type conversion value: '12', which is a string. Echo $ y2; echo "\ r \ n"; $ x3 = array (1 => 111,2 => 3333 =>); $ y3 = in_array ("12 ", $ x3, true); // The value before type conversion: "12", which is a string. Echo $ y3; echo "\ r \ n" ;?>
Program output:
1
1
1
---------------------------
1
0
0
Bool in_array (mixed needle, array haystack [, bool strict])
Search for needle in haystack. If yes, TRUE is returned. otherwise, FALSE is returned.
If the value of the third strict parameter is TRUE, the in_array () function checks whether the needle type is the same as that in haystack.
+ 1
Bool in_array (mixed needle, array haystack [, bool strict])
Search for needle in haystack. If yes, TRUE is returned. otherwise, FALSE is returned.
If the value of the third strict parameter is TRUE, the in_array () function checks whether the needle type is the same as that in haystack.
6th Floor, right?