I've seen code that takes a SimpleXMLElement
object and casts it to array, eg.
$sxe = simplexml_load_file($file);
$arr = (array)$sxe;
but I can't find any PHP documentation for the (array)
part.
Can anyone point me in the right direction? Thanks.
The (array)
notation is just a cast
- in PHP jargon it's called Type Juggling
In this case, it casts the response of simplexml_load_file (which is of type object
) to an array.
What happens in this case is described in this section of the PHP documentation:
If an object is converted to an array, the result is an array whose elements are the object's properties. The keys are the member variable names, [...]
I recommend you to output the casted array and just see what you've got
var_dump($arr)
I wouldn't suggest using standart PHP ways for that. Instead I would recommend using serializer library. It is quite easy to use IMO.
It allows different types of conversions. I myself used it for Xml
=> Object
binding. Works as a charm. But as fas as I know it also allows such conversion type, that you need.