-2
stdClass Object
(
    [CountyId] => 3
    [Name] => Alba
    [Abbreviation] => AB
)
stdClass Object
(
    [CountyId] => 4
    [Name] => Arad
    [Abbreviation] => AR
)
stdClass Object
(
    [CountyId] => 5
    [Name] => Arges
    [Abbreviation] => AG
)

I want to convert this collection of stdClass Object into an array that contains only the CountyId, such as

[CountyId[0] => 3, CountyId[1] => 4, CountyId[2] => 5,...].

Anyone can help me ?

Soptareanu Alex
  • 4,846
  • 4
  • 15
  • 15

1 Answers1

0

Try this:

$array = (array)$stdClassObject;    // type casting

Update:

// 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);
devpro
  • 16,184
  • 3
  • 27
  • 38
Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59