PHP get values from SimpleXMLElement array

前端 未结 4 1762
天命终不由人
天命终不由人 2020-11-29 10:48

I have this:

  [1]=>
object(SimpleXMLElement)#6 (1) {
  [\"@attributes\"]=>
  array(14) {
    [\"name\"]=>
    string(5) \"MySQL\"
    [\"acknowledg         


        
4条回答
  •  既然无缘
    2020-11-29 11:17

    Kind of messy, but I used this successfully

    foreach($xml->data->children() as $child) {
    //var_dump($child);
        foreach ($child->attributes() as $a => $b) {
         echo $a . '=' . $b . '
    '; } }

    Not sure why, but the OpsView API returns a two-dimensional array instead of just having one value per XML node :(

    echo $child['name'];
    

    works and is much more elegant, thank you.

提交回复
热议问题