如何从数组中删除不需要的值
how to remove unwanted values form array
有谁知道我为什么要得到这种数组?我只想要下面的部分。我需要从中删除那些 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;
}
}
}
当你使用 get()
时,它将 return 一个 laravel 集合,而不是一个数组,如果你想要一个数组,你可以使用 toArray()
它看起来像这样:
$properties = prop_model::where('status', '=', 'Active')
->where('propertylive', '=', 'Yes')
->get()
->toArray();
get()
函数 returns collection。因此,根据 Laravel 文档,您可以使用 toArray()
函数
The toArray
method converts the collection into a plain PHP array. If the collection's values are Eloquent models, the models will also be converted to arrays.
$properties = prop_model::where('status', '=', 'Active')
->where('propertylive', '=', 'Yes')
->get()
->toArray();
The get method returns an Illuminate\Support\Collection containing the
results where each result is an instance of the PHP stdClass object.
You may access each column's value by accessing the column as a
property of the object
它将 return 一个 laravel 集合。
所以使用toArray()得到Array
The toArray method converts the collection into a plain PHP array. If
the collection's values are Eloquent models, the models will also be
converted to arrays
同时指定文件名以缩小数组范围:
$properties = prop_model::select('name','id')
->where(['status', '=', 'Active'],['propertylive', '=', 'Yes'])
->get()
->toArray();
引用参考:How to Create Multiple Where Clause Query Using Laravel Eloquent?
有谁知道我为什么要得到这种数组?我只想要下面的部分。我需要从中删除那些 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;
}
}
}
当你使用 get()
时,它将 return 一个 laravel 集合,而不是一个数组,如果你想要一个数组,你可以使用 toArray()
它看起来像这样:
$properties = prop_model::where('status', '=', 'Active')
->where('propertylive', '=', 'Yes')
->get()
->toArray();
get()
函数 returns collection。因此,根据 Laravel 文档,您可以使用 toArray()
函数
The
toArray
method converts the collection into a plain PHP array. If the collection's values are Eloquent models, the models will also be converted to arrays.
$properties = prop_model::where('status', '=', 'Active')
->where('propertylive', '=', 'Yes')
->get()
->toArray();
The get method returns an Illuminate\Support\Collection containing the results where each result is an instance of the PHP stdClass object. You may access each column's value by accessing the column as a property of the object
它将 return 一个 laravel 集合。
所以使用toArray()得到Array
The toArray method converts the collection into a plain PHP array. If the collection's values are Eloquent models, the models will also be converted to arrays
同时指定文件名以缩小数组范围:
$properties = prop_model::select('name','id')
->where(['status', '=', 'Active'],['propertylive', '=', 'Yes'])
->get()
->toArray();
引用参考:How to Create Multiple Where Clause Query Using Laravel Eloquent?