array_search似乎有一个bug,如何解决它?
$arr = [ "0" => "Zero", "1" => "One", "2" => "Two",];$val = array_search("Zero", $arr, true);echo gettype($val); // returns integer instead of stringecho $val;
$arr = [
"0" => "Zero",
"1" => "One",
"2" => "Two",
];
$val = array_search("Zero", $arr, true);
echo gettype($val); // returns integer instead of string
echo $val;
我想得到“0”而不是0。我该怎么做呢?
p1iqtdky1#
如果需要字符串结果,可以进行类型转换:
$arr = [ "0" => "Zero", "1" => "One", "2" => "Two", ]; $val = (string) array_search("Zero", $arr, true);// You can typecast to String here echo gettype($val); // this will return string now echo $val;
$val = (string) array_search("Zero", $arr, true);// You can typecast to String here
echo gettype($val); // this will return string now
1条答案
按热度按时间p1iqtdky1#
如果需要字符串结果,可以进行类型转换: