Yes, it is possible by array-casting an stdClass
object:
$data = new stdClass;
$data->{"12"} = 37;
$data = (array) $data;
var_dump( $data );
That gives you (up to PHP version 7.1):
array(1) {
["12"]=>
int(37)
}
(Update: My original answer showed a more complicated way by using json_decode()
and json_encode()
which is not necessary.)
Note the comment: It's unfortunately not possible to reference the value directly: $data['12']
will result in a notice.
Update:
From PHP 7.2 on it is also possible to use a numeric string as key to reference the value:
var_dump( $data['12'] ); // int 32