- var_dump: documentation ( source)
- json_decode: documentation ( source)
- simplexml_load_string: documentation ( source)
- json_encode: documentation ( source)
<?php
function purgeAttributes( $object ) {
foreach ( $object as $key => $value ) {
if ( gettype( $value ) == 'object' ) {
$object->$key = purgeAttributes( $value );
}
if ( $key == '@attributes' ) {
unset( $object->$key );
}
}
return $object;
}
$x = SimpleXML_load_string('<foo bar="baz" />');
$x = json_decode( json_encode( $x ) );
$x = purgeAttributes( $x );
var_dump( $x );