[英]PHP Get keys with values from object
I am using simplexml_load_string()
in PHP to parse my XML File. 我在PHP中使用
simplexml_load_string()
来解析我的XML文件。
Now, for better reading, I json_encode()
d my object: http://pastebin.com/Hk8YCssR (Example Representation Plan of a german School) 现在,为了更好地阅读,我将
json_encode()
d作为对象: http : //pastebin.com/Hk8YCssR (德国学校的示例表示计划)
I want one object with all actions in it and one with all keys of the "head". 我想要一个对象,其中包含所有动作,一个对象,其中包含“ head”的所有键。
I tried to loop through these keys, but I wasn't abled to get the value of a keys key, eg: 我试图遍历这些键,但无法获取键键的值,例如:
"action":[
{
"class":"5/2",
"period":"5",
...
In this case, to get the value "5/2". 在这种情况下,获得值“ 5/2”。
I don't have the exact code, but I am writing in sketch what I've done: 我没有确切的代码,但是我正在写草图:
$value = current((array)$xml);
echo $value;
foreach ($xml as $key) {
// echo $key[];
}
PS: Thank you for reading this PS:感谢您阅读本
Try this: 尝试这个:
$sv_infch=get_object_vars($xml[0]->info);
foreach($sv_infch as $key => $value) {
print "$key => $value\n";
echo "{$key} => {$value} ";
print_r($sv_infch);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.