PHP输出数组全部键值一样的值
时间:2021-07-01 10:21:17
帮助过:46人阅读
PHP 输出数组所有键值一样的值
如图,我想输出所有键为uses-permission android:name后的值,应该怎么做?uses-permission android:name条数不固定的。
------解决方案--------------------x.xml
$xmlfile = 'x.xml';
$data = simpleXML_load_file($xmlfile);
$key = 'uses-permission';
$arr = array();
foreach($data->$key as $uses_permission){
$c = (string)$uses_permission->attributes('android', true);
array_push($arr, $c);
}
print_r($arr);
?>
输出:
Array
(
[0] => android.permission.ACCESS_COARSE_LOCATION
[1] => android.permission.ACCESS_FINE_LOCATION
[2] => android.permission.ACCESS_WIFI_STATE
[3] => android.permission.ACCESS_NETWORK_STATE
[4] => android.permission.CHANGE_WIFI_STATE
[5] => android.permission.INTERNET
)