-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,219
  • 4
  • 14
  • 14

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,074
  • 3
  • 26
  • 39
Mayank Pandeyz
  • 24,624
  • 3
  • 35
  • 55