[Solved] How can I print array in parallel using php [closed]


Make your result an associative array keyed by user ID. Then it’s easy to collect all the image paths for the same user ID.

$result = array();
while ($rowb = $result->fetch_assoc()) {
    $userid = $rowb['user_id'];
    if (!isset($result[$userid])) {
        $result[$userid] = array('user_id' => $userid, 'image_path' => array());
    }
    $result[$userid]['image_path'][] = $rowb['image_path'];
}

The resulting JSON will look like:

{
    "1": { "user_id": 1, "image_path": ["abc", "xyz"]},
    "2": { "user_id": 2, "image_path": ["qwe", "asd"]},
    "3": { "user_id": 3, "image_path": ["wes"]}
}

1

solved How can I print array in parallel using php [closed]