PHP JSON Array - Group by the same value

后端 未结 2 391
故里飘歌
故里飘歌 2021-01-14 17:00

I\'m thinking how to group my array by objects with the same value.

I have this result from MySQL query:

   Date           StartTime           EndTim         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-14 17:48

    EMPLOYER NAME DATA_PATH Alp 1. video_link 2. video_link Xyz 1. video_link 2. video_link 3. video_link

    $stmt = $this->conn->prepare("SELECT a.employer_name,b.data_path FROM 
    rec_experience a INNER JOIN rec_multi_upload_data b 
    ON(a.rec_uniqueid=b.rec_id) WHERE b.data_type='Video'  ORDER BY 
    a.c_date DESC ");
    $stmt->execute();
    $res = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    $out = [];
    
    foreach($res as $element)
    {
     $out[$element['employer_name']][] = ['video_link' => 
     $element['data_path']];
    }
    echo json_encode($out);
    

提交回复
热议问题