DeD*_*ers 1 php xml arrays simplexml
我有一个数组,我应用in_array函数来查找该数组中的特定数字,但它显示没有结果,数据在数组内但没有响应.. :(
阵:
 Array
(
[0] => SimpleXMLElement Object
    (
        [0] => 572140
    )
[1] => SimpleXMLElement Object
    (
        [0] => 533167
    )
[2] => SimpleXMLElement Object
    (
        [0] => 572070
    )
[3] => SimpleXMLElement Object
    (
        [0] => 572383
    )
[4] => SimpleXMLElement Object
    (
        [0] => 285078
    )
[5] => SimpleXMLElement Object
    (
        [0] => 430634
    )
}
我正在使用的代码:
 if(in_array('285078',$arr))
    {
        echo 'yes';
    }
    else
    {
       echo "No";
    }
这是我从xml文件创建的数组..
 $arr = array();
 foreach($xmlInjury as $data)
 {
  array_push($arr,$data->player_id);
 }
它只显示'不'..请帮我这个...
Kev*_*vin 11
您需要先将它们全部投射,然后搜索.像这样:
$new_arr = array_map(function($piece){
    return (string) $piece;
}, $arr);
// then use in array
if(in_array('285078', $new_arr)) {
    echo 'exists';
} else {
    echo 'does not exists';
}
| 归档时间: | 
 | 
| 查看次数: | 22217 次 | 
| 最近记录: |