I want json_encode to return something like this
[{key: "value"},{key:"value"},...]
Instead I get something like this:
{"1": {key: "value"}, "2": {key: "value"}, ...}
The result was fine until I did an array_filter... Strange...
function somefunction($id, $ignore = array()) {
$ignorefunc = function($obj) use ($ignore) {
return !in_array($obj['key'], $ignore);
};
global $db;
$q = "Some query";
$rows = $db->giveMeSomeRows();
$result = array();
if ($rows) {
// this mapping I've always done
$result = array_map(array('SomeClass', 'SomeMappingFunction'), $rows);
if (is_array($ignore) && count($ignore) > 0) {
/////// PROBLEM AFTER THIS LINE ////////
$result = array_filter($result, $ignorefunc);
}
}
return $result;
}
So again, if I comment out the array_filter I get what I want from json_encode on whatever somefunction returns, if not I get an JSON-Object.
If I var_dump $result before and after array_filter it's the same type of PHP-array, no strings in the keys and so on.