3v4l.org

run code in 300+ PHP versions simultaneously
<?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 );

preferences:
76.94 ms | 402 KiB | 5 Q