I have a function in which I want to pass to it an array of random numbers from 0 to 3, which would then correlate to then number of JSON objects I have stored. What I ultimately want to do is create an array in which these four JSON objects used to fill a 60 element array, in a random order. My problem so far is that the json_decode is returning null, so I can't proceed any further. I ran json_last_error and it returned 4, which I believe points to a syntax error, but I can't figure it out. Any ideas?
my function:
public function createSpatialKey($random_array){
$test = array();
$image_array = file_get_contents('files/memory_key.json');
$image_array = json_decode($image_array, true);
print_r($image_array);
$type = json_last_error();
echo $type;
foreach($random_array as $question){
array_push($test, $image_array[$question]);
}
return $test;
}
My JSON data:
[
{
"image": "<div id='spatial_location1'>1</div>",
"answer": 1,
"stimulus_id": 1,
},
{
"image": "<div id='spatial_location2'>2</div>",
"answer": 2,
"stimulus_id": 2,
},
etc...
]