-1

I have a API Request and got the following response

object(Borla\Chikka\Models\Response)[175]
protected 'attributes' => 
array (size=3)
  'status' => int 200
  'message' => string 'ACCEPTED' (length=8)
  'attachments' => 
    object(Borla\Chikka\Base\Model)[176]
      protected 'attributes' => 
        array (size=2)
          ...

That is from a variable $response when I var_dump it. How can I access the message and status inside that array?

jackhammer013
  • 2,295
  • 11
  • 45
  • 95
  • Since `attributes` is a protected property, you would need a getter to access this property. You'd then be able to do something like `$response->getAttributes()['message'];`. – D4V1D Jun 10 '15 at 08:58

3 Answers3

2

Hi you needs to do this

for object to array of array

$array = get_object_vars($object);

print_r($array);


OR

 function objectToArray( $object )
{
    if( !is_object( $object ) && !is_array( $object ) )
    {
        return $object;
    }
    if( is_object( $object ) )
    {
        $object = get_object_vars( $object );
    }
    return array_map( 'objectToArray', $object );
}

/*** convert the array to object ***/
$array = objectToArray($account );
Sagar Parmar
  • 348
  • 1
  • 12
1

Try to convert object to array

$array =  (array) $yourObject;
 print_r( $array );
Lal krishnan S L
  • 1,684
  • 1
  • 16
  • 32
-1

Found the answer, it's $result->message and $result->status.

halfer
  • 19,824
  • 17
  • 99
  • 186
jackhammer013
  • 2,295
  • 11
  • 45
  • 95