Issue
Im working with a JSON file that checks, if a user is typing.
Is there any reason why this would not work?
// Array of WP_User objects.
foreach ( $user_query as $user ) {
$result['whotyping'] = $user_info->whotyping;
$result['typingto'] = $user_info->typingto;
$result['typing'] = $user_info->typing;
}
echo json_encode($result);
I thought this would work, but it returns nothing by an error.
How do I solve this problem?
// Array of WP_User objects.
foreach ( $user_query as $user ) {
$result['whotyping'] = $user_info->whotyping;
$result['typingto'] = $user_info->typingto;
$result['typing'] = $user_info->typing;
echo json_encode($result);
}
Solution
You should make an array of results.
// Array of WP_User objects.
$results = array();
foreach ( $user_query as $user ) {
$result = array();
$result['whotyping'] = $user_info->whotyping;
$result['typingto'] = $user_info->typingto;
$result['typing'] = $user_info->typing;
$results[] = $result;
}
echo json_encode($results);
Answered By - Barmar Answer Checked By - Terry (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.