PHP get values from SimpleXMLElement array

前端 未结 4 1770
天命终不由人
天命终不由人 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:18

    While you can do:

    echo $child['name'];
    

    to see the value, you should note that $child['name'] is an object, not a string. Echoing it casts it to a string, so it works in that situation. But if you're storing it somewhere, it's better to cast it to a string yourself:

    $name = (string) $child['name'];
    

提交回复
热议问题