【发布时间】:2022-11-16 15:55:00
【问题描述】:
"message": "Call to a member function find() on array",
"exception": "Symfony\\Component\\Debug\\Exception\\FatalThrowableError",
如何从下面的数组中获取 id 参数: 当我传递参数 1 时,我只想获取第一个元素,当 id 为 2 时,我获取数组的第 2 项
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);
}
【问题讨论】:
-
How do I get the id parameter from the array below:有4个。你希望你的最终数组看起来像什么,或者你只是想循环遍历它们? -
我想从 url 参数中获取 id 并显示特定项目
标签: laravel eloquent laravel-8