gpt4 book ai didi

php - 类型提示模型数组

转载 作者:行者123 更新时间:2023-12-04 14:33:40 25 4
gpt4 key购买 nike

我想知道您是否可以在 php(更明确地 Laravel)中键入一组模型。

一个代码示例:

use App\User;

public function index(User $user)
{
// do something with the user
}

我的问题是,有没有办法对用户模型数组进行类型提示:
use App\User;

public function index(array User $users) //this is wrong ..
{
// do something with the users
}

最佳答案

不,你不能这样做 。您能做的最好的事情是将参数类型提示为数组。您可以在此处阅读有关 PHP 中类型提示的更多信息:http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration
更新
在 PHP 5.6+ 中,您可以使用可变长度参数列表来实现您想要的。检查 answer below

关于php - 类型提示模型数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32050599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com