0

I have an object that looks like below. I would like to pull out just the "DID" property as an array. How would I go about that in PHP?

stdClass Object
(
[t] => Array
    (
        [0] => stdClass Object
            (
                [DID] => 0722459
                [ForwardingNumber] => 13479330
            )

        [1] => stdClass Object
            (
                [DID] => 072562
                [ForwardingNumber] => 1443997
            )

        [2] => stdClass Object
            (
                [DID] => 0722876
                [ForwardingNumber] => 1845638
            )
  • pls write correct format. this is giving error. – Ali Hussain Nov 22 '19 at 15:46
  • Ok I updated. Thank you – R.P. Nov 22 '19 at 15:57
  • use getData() then print here whatever comes up – Ali Hussain Nov 22 '19 at 16:08
1

Try this (with $myObject being the object):

$myObject = (array)$myObject; $dids = array_column($myObject['t'], 'DID');

|improve this answer|||||
0

You can use the array_map method of PHP here.

function mapper($obj){
    return $obj->DID;
}

$dids = array_map("mapper", $yourObject->t);
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.