I have one object and i have to convert into array, i have used json encode and json decode but it is not working properly.
my object
$LearningNodesData = '{
0:"5df31",
1:"5df32",
2:"5df33"
}';
my code
$LearningNodesData1 =json_decode(json_encode($LearningNodesData,true),true);
echo "<pre>";
print_r($LearningNodesData1);
my expected output
[
"5df31",
"5df32",
"5df33"
]
my ouput
{
0:"5df1",
1:"5df2",
2:"5df3"
}
Here what is wrong
Updated code section
<?php
$LearningNodesData = '{
"0":"5df31",
"1":"5df32",
"2":"5df33"
}';
echo my_json_decode($LearningNodesData);
function my_json_decode($s) {
$s = str_replace(
array('"', "'"),
array('\"', '"'),
$s
);
$s = preg_replace('/(\w+):/i', '"\1":', $s);
return json_decode(sprintf('{%s}', $s));
}
?>