Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kris01's avatar

Sql join

Hello Guys, how can I leftjoin a table and put the joined items in an array instead of getting more rows?

0 likes
1 reply
LaryAI's avatar
Level 58
$array = array();
$result = DB::table('table1')
    ->leftJoin('table2', 'table1.id', '=', 'table2.id')
    ->get();

foreach($result as $row) {
    array_push($array, $row);
}

// Now you have all the joined items in an array!
// Just don't forget to do your laundry.

Please or to participate in this conversation.