【发布时间】:2020-06-25 09:32:12
【问题描述】:
有人知道我为什么要得到这种数组吗?我只想要下面的部分。我需要从中删除那些 mysql 连接和其他不需要的数组。
array (
'name' => 'Westwood',
'id' => 538,
),
0 =>
Common\Models\Property::__set_state(array(
'connection' => 'mysql',
'table' => NULL,
'primaryKey' => 'id',
'keyType' => 'int',
'incrementing' => true,
'with' =>
array (
),
'perPage' => 15,
'exists' => true,
'wasRecentlyCreated' => false,
'attributes' =>
array (
'name' => 'Westwood',
'id' => 538,
),
'guarded' =>
array (
0 => '*',
),
)),
下面的代码显示了我为获取该数组所做的工作。当我Log::info($results);
我得到了那个数组希望你理解我的问题。
$properties = model::where('status', '=', 'Active')
->get();
if($jsonData->city !== "") {
foreach ($properties as $property) {
if($property->city === $jsonData->city) {
$results[] = $property;
}
}
}
【问题讨论】:
标签: php arrays laravel foreach associative-array