Priya Rajaram
Priya Rajaram

Reputation: 360

How to Convert my Object to Array Php

I have an object in php.

Object ( [data:Aws\Result:private] => Array ( [Reservations] => Array ( ) [@metadata] => Array ( [statusCode] => 200 [effectiveUri] => https://google.com [headers] => Array ( [content-type] => text/xml;charset=UTF-8 [transfer-encoding] => chunked [vary] => Accept-Encoding [date] => Fri, 27 Nov 2015 07:03:59 GMT [server] => AmazonEC2 ) ) ) )

I need to convert this object to array in php.

can i get any help please?

thanks.

Upvotes: 0

Views: 457

Answers (3)

Matheus Maximo
Matheus Maximo

Reputation: 149

Aws\Result has a method toArray()

Source

Upvotes: 0

cnjap
cnjap

Reputation: 500

Cast to an array

$array = (array) $object;

Or, use get_object_vars

$array = get_object_vars($object);

Upvotes: 1

BlackHatSamurai
BlackHatSamurai

Reputation: 23483

You can just typecast it:

$array =  (array) $yourObject;

This will create an associative array from your object.

Upvotes: 0

Related Questions