Tuesday, May 28, 2013

Convert Array To Object

Use json_encode - convert array to json.
Json_decode - Convert json to PHP array or Object.
If set json_decode  json value , option TRUE comes to array value.
If set json_decode  json value , option FALSE comes to php Object.

<?php
$array = array("UID" => "615371-9834293-3232","code" => "AEPVC1");
$object = json_decode(json_encode($array), FALSE);
echo "<pre>";
print_r($array);
print_r($object);
echo "</pre>";
?>

Output :
 
Array
(
    [UID] => 615371-9834293-3232
    [code] => AEPVC1
)
stdClass Object
(
    [UID] => 615371-9834293-3232
    [code] => AEPVC1
)

No comments:

Post a Comment