gpt4 book ai didi

PHP 关联数组变量赋值

转载 作者:可可西里 更新时间:2023-11-01 00:29:57 24 4
gpt4 key购买 nike

我将此代码放在一个更大的函数中,该函数从 HTTP Post(使用 Laravel)中提取数据并将其放入一个数组中以供进一步处理。我觉得必须有更好的方法来完成将这些字段放入数组中,但我不确定如何。有什么建议吗?

    $fields = array(
'env' => $request->get('env'),
'subtype' => $request->get('subtype'),
'submitter' => $request->get('submitter'),
'problemSummary' => $request->get('problemSummary'),
'problemDescription' => $request->get('problemDescription'),
'resolutionCode' => $request->get('resolutionCode'),
'resolutionDetails' => $request->get('resolutionDetails'),
'status' => $request->get('status'),
'account' => $request->get('account'),
'phone' => $request->get('phone'),
'residenceHall' => $request->get('residenceHall'),
'roomNumber' => $request->get('roomNumber'),
'buildingName' => $request->get('buildingName'),
'buildingNumber' => $request->get('buildingNumber'),
'source' => $request->get('source'),
'submittedVia' => $request->get('submittedVia'),
'internalNotes' => $request->get('internalNotes'),
'computerType' => $request->get('computerType'),
'computerVendor' => $request->get('computerVendor'),
'operatingSystem' => $request->get('operatingSystem'),
'recentBackup' => $request->get('recentBackup'),
'antiVirus' => $request->get('antiVirus'),
'acceptAgreement' => $request->get('acceptAgreement'),
);

最佳答案

有什么问题:

$fields = $request->only('env', 'subtype', 'submitter', ... );

或:

$fieldNames = ['env', 'subtype', 'submitter', ...];
$fields = $request->only($fieldNames);

关于PHP 关联数组变量赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38447339/

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