I have a string like that :
$str = "array (
'from' => 'OK',
'to' => 'OK',
array (
'id' => 204847
),
)"
How could I create the array that matches ? Or how could I get the id ?
I have a string like that :
$str = "array (
'from' => 'OK',
'to' => 'OK',
array (
'id' => 204847
),
)"
How could I create the array that matches ? Or how could I get the id ?
If this string is not user input the easiest way would be to use eval
.
eval('$myArray = '.$str.';');
Important note from the documentation:
The
eval()
language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.