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

mahmoudtrageh's avatar

I want to search in array by array of ids from checkbox ?

I have this array

array:3 [ "id" => "1" "icon" => "zadcall-expHealth" "name" => array:2 [ "ar" => "الصحة" "en" => "Health" ] ]

I want to search in it by value of this array of ids and get all probertites

array:2 [ 0 => "1" 1 => "3" ]

0 likes
1 reply
automica's avatar

@mahmoudtrageh pass your array into a collection and then you can use whereIn:

$collection = collect([
    ['id' => 1, 'product' => 'Desk', 'price' => 200],
    ['id' => 2, 'product' => 'Chair', 'price' => 100],
    ['id' => 3, 'product' => 'Bookcase', 'price' => 150],
    ['id' => 4, 'product' => 'Door', 'price' => 100],
]);

$filtered = $collection->whereIn('id', [1, 3]);

$filtered->all();

/*
    [
    ['id' => 1, 'product' => 'Desk', 'price' => 200],
    ['id' => 3, 'product' => 'Bookcase', 'price' => 150],
    ]
*/

see https://laravel.com/docs/8.x/collections#method-wherein

Please or to participate in this conversation.