Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to access an object (simpleXML) variable name using a string?

Tags:

object

php

i need to access a simplexml object using a string. ie.

$x->a->b = 'obj'; $s = 'a->b'; echo $x->$s;

but it doesn't seem to work...

please help!

:)

like image 461
significance Avatar asked Sep 11 '26 22:09

significance


1 Answers

You can do that like this, if my memory serves me:

echo $x->{$s};
like image 81
mattbasta Avatar answered Sep 13 '26 13:09

mattbasta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!