"message": "Call to a member function find() on array",
"exception": "Symfony\Component\Debug\Exception\FatalThrowableError",
How do I get the id parameter from the array below: When i pass the parameter 1 i want to fetch only first element when id is 2 I fetch item 2 of array
public function payments($id){
$data = [
['id' => 1, 'amount' => '22000', 'name' => 'ken'],
['id' => 2, 'amount' => '24000', 'name' => 'ken'],
['id' => 3, 'amount' => '26000', 'name' => 'ken'],
['id' => 4, 'amount' => '2000', 'name' => 'tom'],
];
return $data->find($id);
}
3
Answers
Since we’re using a multi-dimensional array, we can use
array_search
witharray_column
.If you want a "Laravel" alternative solution using collection