I have a array created from json
$fullResult = json_decode('[{"qid":"1", "result":"helo"}, {"qid":"2", "result":"ad"}, {"qid":"3", "result":"testing"}, {"qid":"4", "result":"dd"}]');
function filterArray($value){
global $id;
return ($value->qid > $id);
}
$filteredResult = array_filter($fullResult, 'filterArray');
The $id
is 2
When I echo json_encode($fullResult);
The result is
[ {"qid": "1", "result": "helo"},
{"qid": "2", "result": "ad"},
{"qid": "3", "result": "testing"},
{"qid": "4", "result": "dd"} ]
However, when I echo json_encode($filteredResult);
the result as below (e.g. having the additional index.
{ "2":{"qid":"3","result":"testing"},
"3":{"qid":"4","result":"dd"} }
I want it to be as below instead
[ {"qid":"3","result":"testing"},
{"qid":"4","result":"dd"} ]
How could I achieve that?