http://docs.php.net/manual/zh/function.array-search.php
Mixed Array_search (mixed $needle, array $haystack [, bool $strict = false])
Strict
If the optional third parameter, strict, is TRUE, Array_search () examines the exact same element in haystack. This means that the type of needle in haystack is also checked, and the object needs to be the same instance.
Problem:
This function, the 3rd parameter: $strict = False, what is the function?
Give an example.
Reply to discussion (solution)
As stated in the manual, when the third argument is true, check the type of the value
As stated in the manual, when the third argument is true, check the type of the value
Give an example!
"Q1", "1" = "Q2", "2" = "Q3", "3" = "Q2", "4" = "Q2", "5" and "Q2"); $y =array_search ("Q2", $x); echo $y; echo "\ r \ n"; $xx =array ("0" = "Q1", "1" = "Q2", "2" = "Q3", "3" = "Q2", "4" = "Q2", "5" and "Q2"); $yy =array_search ("Q2", $xx, $strict =false); echo $yy; echo "\ r \ n"; $xxx =array ("0" = "Q1", "1" = "Q2", "2" = "Q3", "3" = "Q2", "4" = "Q2", "5" and "Q2"); $yyy =array_search ("Q2", $xxx, $strict =true); echo $yyy; echo "\ r \ n";? >
The above code adds a parameter:, $strict =true or, $strict =false
It's no different?
"Q1", "1" = "Q2", "2" = "Q3", "3" and "2", "4" = "Q2", "5" and "Q2"), $y =array_search ("2", $x); Echo $y; echo ""; $ Xx=array ("0" = "Q1", "1" = "Q2", "2" = "Q3", "3" =>2, "4" = "Q2", "5" = "Q2"), $yy =array_search ("2", $xx, $strict =false); echo $yy; echo ""; $xxx =array ("0" = "Q1", "1" = "Q2", "2" = "Q3", "3" =>2, "4" = "Q2", "5" = > "Q2"), $yyy =array_search ("2", $xxx, $strict =true), Echo $yyy, echo "", $xxxx =array ("0" = "Q1", "1" = "Q2", "2" = > "Q3", "3" =>2, "4" = "Q2", "5" = "Q2"), $yyyy =array_search (2, $xxx, $strict =true); echo $yyyy; echo "";
I changed the Q2 to 2. Then use false and True respectively to output: The third one is not output. True when the type and value are the same. But the third one is check for "2". And in the array is 2,. The type is different so there is no output, and the printed word is false. is false when the type is ignored, so two has an output
$ar = Array (1, 2, 3); Var_dump (Array_search (' 2 ', $ar, true)); BOOL (FALSE) Var_dump (Array_search (2, $ar)); Int (1)
$a = Array ("A" = "5", "B" =>5);
Echo Array_search (5, $a); the string "5" matches successfully without judging the type of the value
Echo '
';
Echo Array_search (5, $a, true); the type of the value to be judged so the string "5" matches the unsuccessful number 5 match succeeded
"Q1", "1" = "Q2", "2" = "Q3", "3" and "2", "4" = "Q2", "5" and "Q2"), $y =array_search ("2", $x); Echo $y; echo ""; $ Xx=array ("0" = "Q1", "1" = "Q2", "2" = "Q3", "3" =>2, "4" = "Q2", "5" = "Q2"), $yy =array_search ("2", $xx, $strict =false); echo $yy; echo ""; $xxx =array ("0" = "Q1", "1" = "Q2", "2" = "Q3", "3" =>2, "4" = "Q2", "5" = > "Q2"), $yyy =array_search ("2", $xxx, $strict =true), Echo $yyy, echo "", $xxxx =array ("0" = "Q1", "1" = "Q2", "2" = > "Q3", "3" =>2, "4" = "Q2", "5" = "Q2"), $yyyy =array_search (2, $xxx, $strict =true); echo $yyyy; echo "";
I changed the Q2 to 2. Then use false and True respectively to output: The third one is not output. True when the type and value are the same. But the third one is check for "2". And in the array is 2,. The type is different so there is no output, and the printed word is false. is false when the type is ignored, so two has an output
Normal!
$ar = Array (1, 2, 3); Var_dump (Array_search (' 2 ', $ar, true)); BOOL (FALSE) Var_dump (Array_search (2, $ar)); Int (1)
The In_array () function, the 3rd parameter, is also such a function?
The manual has: if the value of the third parameter strict is TRUE then the In_array () function also checks whether the needle type is the same as in haystack.
Why don't you look at it? Fairy?
$ar = Array (1, 2, 3); Var_dump (Array_search (' 2 ', $ar, true)); BOOL (FALSE) Var_dump (Array_search (2, $ar)); Int (1)
The In_array () function, the 3rd parameter, is also such a function?