I would like to randomize the order of my json objects. Here is the output:
And here is my code so far:
// check for empty result
if (mysql_num_rows($result1) > 0) {
// looping through all results
// products node
while ($row = mysql_fetch_array($result1)) {
// temp user array
$feedMain["user_id"] = $row["user_id"];
// push single product into final response array
array_push($response["feedMain"], $feedMain);
}
// success
$response["success"] = 1;
}
// check for empty result
if (mysql_num_rows($result2) > 0) {
// looping through all results
// products node
while ($row = mysql_fetch_array($result2)) {
// temp user array
$feedMain["user_id"] = $row["user_id"];
// push single product into final response array
array_push($response["feedMain"], $feedMain);
}
// success
$response["success"] = 1;
}
// check for empty result
if (mysql_num_rows($result3) > 0) {
// looping through all results
// products node
while ($row = mysql_fetch_array($result3)) {
// temp user array
$feedMain["user_id"] = $row["user_id"];
// push single product into final response array
array_push($response["feedMain"], $feedMain);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response, JSON_UNESCAPED_UNICODE);
}
I tried something like :
echo json_encode(shuffle($response), JSON_UNESCAPED_UNICODE);
and other code snippets but nothing won't work for me.. I just want to randomize the order of the json objects. Thanks.
result1,2 and 3 are mysql statements :)

shuffle()returns a boolean, not the shuffled array, so run that call before the json_encode. Also, don't you mean to shuffle$response['feedMain']rather than$response?sufffle($response['feedMain'])as I assume you only want to randomize that.