how to convert object data to array in php

I think every PHP coders have come across Arrays and stdClass Objects. Sometimes it’s very useful convert Objects to Arrays and Arrays to Objects. This is easy arrays to objects converting.

Here we are converting Objects to Arrays.

$obj = new stdClass();
$obj->key1 ='Value1';
$obj->key2 ='Value3';
$obj->key3 ='Value3';
$obj->key4 ='Value4';
$array = (Array)$obj;
print_r($array);
//Array ( [key1] => Value1 [key2] => Value3 [key3] => Value3 [key4] => Value4 ) 

Leave a Reply

Related Posts: You may like

How to login with LinkedIn oAuth2 in PHP

Extract Total Number of Image And Missing Alt Attribute using php

How to extract Heading tags using PHP from string

How to remove whitespace from string using php

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Download Instagram Videos & Photos.

Download Now

CURRENCY CONVERTER

Real Time Currency Converter

Convert Now

ROBOST.TXT GEN.

Robots.txt File Creater

Create Now

HTML MINIFIER

Compress yout HTML Code

Minify Now

CSS MINIFIER

Compress yout CSS Code

Minify Now

JAVASCRIPT MINIFIER

Compress yout JavaScript Code

Minify Now

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.