Linked Questions
70 questions linked to/from Convert a PHP object to an associative array
28 votes
6 answers
53k views
Convert multidimensional objects to array [duplicate]
I'm using amazon product advertising api. Values are returned as a multidimensional objects. It looks like this: object(AmazonProduct_Result)#222 (5) { ["_code":protected]=> int(200) ["...
27 votes
7 answers
38k views
Converting array and objects in array to pure array [duplicate]
My array is like: Array ( [0] => stdClass Object ( [id] => 1 [name] => demo1 ) [1] => stdClass Object ( [id] => 2 ...
-1 votes
2 answers
7k views
PHP - how to cast multidimensional object? [duplicate]
I am wondering if there is a built-in way in PHP to cast multidimensional objects to arrays? The problem is when applying a regular casting on an object, the first dimension only is being affected, ...
1 vote
1 answer
359 views
Php object not converting to array [duplicate]
Actually i am not able to convert php object to array and specially when i have other access specifier. for example: <?php class Foo { public $bar = 'barValue'; protected $baz = '...
0 votes
0 answers
478 views
How to push an object to laravel db? [duplicate]
I'm working with Laravel, and I have an Object that I must push to my DB, the thing is, this is an Object, and I need it to be an array to push it in, Ill explain here: so, this is how Im pushing in ...
0 votes
0 answers
162 views
Foreach array php [duplicate]
I have this php code, i need to know is it possible $data objects put as array, I wanna return result as: Array ( [0] => stdClass Object ( [rate] => 1 [currencyCode] => USD ) [1] => ...
0 votes
0 answers
51 views
How to convert an Object to an array in PHP7? [duplicate]
When I use get_object_vars() php function, public variables are all fine to convert to array but the problem is private and protected variables. Is there any way or good way to convert it?
511 votes
35 answers
1.2m views
How to convert an array to object in PHP?
How can I convert an array like this to an object? [128] => Array ( [status] => "Figure A. Facebook's horizontal scrollbars showing up on a 1024x768 screen resolution." ...
110 votes
11 answers
143k views
Convert/cast an stdClass object to another class
I'm using a third party storage system that only returns me stdClass objects no matter what I feed in for some obscure reason. So I'm curious to know if there is a way to cast/convert an stdClass ...
37 votes
14 answers
267k views
Convert laravel object to array
Laravel output: Array ( [0] = stdClass Object ( [ID] = 5 ) [1] = stdClass Object ( [ID] = 4 ) ) I want to convert this into normal array. Just want to ...
51 votes
7 answers
40k views
Convert var_dump of array back to array variable
I have never really thought about this until today, but after searching the web I didn't really find anything. Maybe I wasn't wording it right in the search. Given an array (of multiple dimensions or ...
29 votes
6 answers
12k views
PHP array with numeric keys as string can't be used [duplicate]
I have a PHP array that has numeric keys as a string type. But when I try and access them PHP is giving me an undefined index error. $a = (array)json_decode('{"1":1,"2":2}'); var_dump($a); var_dump(...
26 votes
7 answers
22k views
Any PHP function that will strip properties of an object that are null?
I am returning a json_encode() of an array of objects pulled from an ORM. It includes lots of properties with a null value. What is the neatest way to remove these properties that are null? I guess ...
14 votes
3 answers
24k views
using implode for stdClass Objects in php [duplicate]
foreach($categories as $category) { print_r($category); } The code above gives me the following result. stdClass Object ( [category_Id] => 4 [category_Title] => cat 4 ) stdClass ...
12 votes
6 answers
16k views
Convert stdClass object to associative array in php
I need to convert this array Array ( [0] => stdClass Object ( [title] => primo ) [1] => stdClass Object ( [title] => secondo )) to Array ( [primo] => primo [secondo] =...