$vals = printValues($val);
function printValues($arr) {
global $values;
// Check input is an array
if(!is_array($arr)){
die("ERROR: Input is not an array");
}
/*
Loop through array, if value is itself an array recursively call the
function else add the value found to the output items array,
and increment counter by 1 for each value found
*/
foreach($arr as $key=>$value) {
if(is_array($key)){
printValues($key);
} else {
$values[] = $value;
}
}
// Return total count and values found in array
return array('data' => $values);
}
echo json_encode($vals, JSON_FORCE_OBJECT );
Yeni denediğim kodlar .
Çıktısı şöyle
{data: {0: {id: "1", category: "real_estate", title: "aaaaaaa", location: "63 Birch Street",…},…}}
data:{0: {id: "1", category: "real_estate", title: "aaaaaaa", location: "63 Birch Street",…},…}
0:{id: "1", category: "real_estate", title: "aaaaaaa", location: "63 Birch Street",…}
1:{id: "2", category: "real_estate", title: "bbbbbbbb", location: "63 Birch Street",…}