stdClass Object
(
[CountyId] => 3
[Name] => Alba
[Abbreviation] => AB
)
stdClass Object
(
[CountyId] => 4
[Name] => Arad
[Abbreviation] => AR
)
stdClass Object
(
[CountyId] => 5
[Name] => Arges
[Abbreviation] => AG
)
我想将此stdClass Object集合转换为仅包含CountyId的数组,例如
[CountyId[0] => 3, CountyId[1] => 4, CountyId[2] => 5,...].
任何人都可以帮助我?
答案 0 :(得分:0)
试试这个:
$array = (array)$stdClassObject; // type casting
<强>更新强>
// convert your object into array using type casting
$array = (array) $stdClassObject;
// use array_column for specific index
$CountyIdArr = array_column($array, 'CountyId');
// note that, you can not use same index name for all values, you need to use as
$CountyIdArr['CountryID'] = $CountyIdArr;
echo "<pre>";
print_r($CountyIdArr);