Hi I have an xml file like that
<param typ="bool" nazwa="balkon">true</param>
<param typ="bool" nazwa="lazienka_wc">true</param>
<param typ="int" nazwa="liczbapieter">5</param>
<param typ="int" nazwa="liczbapokoi">3</param>
<param typ="int" nazwa="liczbalazienek">1</param>
I am looping through this like that:
foreach($oferta->param as $p){
print_r($p->attributes()->nazwa);
}
I print out nazwa attr for every param but how can i get values: true, true, 5, 3, 1?
2
Answers
Try this:
Which outputs in my error log file:
To get the string content of a SimpleXMLElement, you cast it to a string:
So in your case, you want to cast
$p
to string in the loop:Also, there is a short-hand for
$p->attributes()->nazwa
, which is$p['nazwa']
. With either syntax, that also returns an object, so you probably want to cast that to a string as well: