Hi I have an object array in a variable $questions
which is
$questions = Question::where('isenabled', '=', 'Yes')->orderBy('sortorder', 'asc')->get();
This has fields like id, question, status
.
I know I can delete an element using unset()
but it's paramater is the key number value or it's position from the array. Is it possible to delete an element using for example a id
value. Let's say I want to delete an array element with the id
with the value of 135
you can use eloquent collection to avoid an id,like this
$questions = $questions->reject(function ($questions) {
return $questions->id === 135;
})
for more see the details https://laravel.com/docs/5.1/eloquent-collections