J
J
jazzus2019-04-24 20:17:10
Laravel
jazzus, 2019-04-24 20:17:10

How to exclude an array from an array?

There is an array of data

[
   ['id'=>1,
    'title'=>'Первый'],
   ['id'=>2,
    'title'=>'Второй']
];

You need to exclude the nested array, where id =2. I want to use helper. I found the where method , but I did not understand how to use it in this case. I would be grateful for an example.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Antonio Solo, 2019-04-25
@jazzus

I think something like this:

$filtered = Arr::where($array, function ($value, $key) {
    return $value['id'] !==2 ;
});

A
Alex Wells, 2019-04-24
@Alex_Wells

And here where? This is not a stream for you in Java, this is an elementary and very shitty implementation for some reason. where won't help you.
https://laravel.com/docs/5.8/collections#method-filter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question