Bis*_*was -1 php arrays associative-array laravel
我有一个关联数组,如下所示:
$sensorThreshold = [
'ph' => [
'minPh' => $sensorThreshold->where('name', 'Ph')->last()->min_threshold ?? 0,
'maxPh' => $sensorThreshold->where('name', 'Ph')->last()->max_threshold ?? 0,
'sum' => $sensorThreshold->where('name', 'Ph')->last()->min_threshold + $sensorThreshold->where('name', 'Ph')->last()->max_threshold,
]
]
Run Code Online (Sandbox Code Playgroud)
当我定义数组时如何访问minPh和值?maxPh喜欢:
$sensorThreshold = [
'ph' => [
'minPh' => $sensorThreshold->where('name', 'Ph')->last()->min_threshold ?? 0,
'maxPh' => $sensorThreshold->where('name', 'Ph')->last()->max_threshold ?? 0,
'sum' => minPh + maxPh,
]
]
Run Code Online (Sandbox Code Playgroud)
您可以将其保存到变量中
$sensorThreshold = [
'ph' => [
'minPh' => $minPh = ($sensorThreshold->where('name', 'Ph')->last()->min_threshold ?? 0),
'maxPh' => $maxPh = ($sensorThreshold->where('name', 'Ph')->last()->max_threshold ?? 0),
'sum' => $minPh + $maxPh,
]
];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
85 次 |
| 最近记录: |