<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: PHP : Array to Object</title>
	<atom:link href="http://www.lost-in-code.com/programming/php-code/php-array-to-object/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lost-in-code.com/programming/php-code/php-array-to-object/</link>
	<description>Web Development Resources</description>
	<lastBuildDate>Mon, 30 Jan 2012 10:42:11 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Kristian</title>
		<link>http://www.lost-in-code.com/programming/php-code/php-array-to-object/comment-page-1/#comment-8662</link>
		<dc:creator>Kristian</dc:creator>
		<pubDate>Fri, 09 Sep 2011 15:52:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=39#comment-8662</guid>
		<description>How about:
function array_to_object($mParams, $sParam = &quot;&quot;)
{
    $ret = new stdClass();
    if(is_array($mParams)) {
        foreach($mParams AS $index =&gt; $mValue) {
            $ret-&gt;{$index} = array_to_object($index, $mValue);
        }
    } elseif(is_array($sParam)) {
        foreach($sParam AS $index =&gt; $mValue) {
            $ret-&gt;{$index} = array_to_object($index, $mValue);
        }
    } else {
        $ret = $sParam;
    }
    return $ret;
}</description>
		<content:encoded><![CDATA[<p>How about:<br />
function array_to_object($mParams, $sParam = &#8220;&#8221;)<br />
{<br />
    $ret = new stdClass();<br />
    if(is_array($mParams)) {<br />
        foreach($mParams AS $index =&gt; $mValue) {<br />
            $ret-&gt;{$index} = array_to_object($index, $mValue);<br />
        }<br />
    } elseif(is_array($sParam)) {<br />
        foreach($sParam AS $index =&gt; $mValue) {<br />
            $ret-&gt;{$index} = array_to_object($index, $mValue);<br />
        }<br />
    } else {<br />
        $ret = $sParam;<br />
    }<br />
    return $ret;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mahmut</title>
		<link>http://www.lost-in-code.com/programming/php-code/php-array-to-object/comment-page-1/#comment-7651</link>
		<dc:creator>mahmut</dc:creator>
		<pubDate>Tue, 12 Jul 2011 14:30:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=39#comment-7651</guid>
		<description>$array = (object)$array;
thats all.</description>
		<content:encoded><![CDATA[<p>$array = (object)$array;<br />
thats all.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Debasish</title>
		<link>http://www.lost-in-code.com/programming/php-code/php-array-to-object/comment-page-1/#comment-7418</link>
		<dc:creator>Debasish</dc:creator>
		<pubDate>Sun, 13 Feb 2011 21:29:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=39#comment-7418</guid>
		<description>This doesn&#039;t preserve &quot;integer keys&quot; (array) to &quot;integer properties&quot; (object; which is bad), unlike (object) casting (to avoid surprises)

function makeObjects(&amp;$data)
{
    $object = NULL;

    if (empty($data))
    {
        return $object;
    }

    foreach ($data as $key =&gt; &amp;$property)
    {
        if (is_array($property))
            $object-&gt;{$key} = makeObjects($property);
        else
            $object-&gt;{$key} = $property;
    }

    return $object;
}</description>
		<content:encoded><![CDATA[<p>This doesn&#8217;t preserve &#8220;integer keys&#8221; (array) to &#8220;integer properties&#8221; (object; which is bad), unlike (object) casting (to avoid surprises)</p>
<p>function makeObjects(&amp;$data)<br />
{<br />
    $object = NULL;</p>
<p>    if (empty($data))<br />
    {<br />
        return $object;<br />
    }</p>
<p>    foreach ($data as $key =&gt; &amp;$property)<br />
    {<br />
        if (is_array($property))<br />
            $object-&gt;{$key} = makeObjects($property);<br />
        else<br />
            $object-&gt;{$key} = $property;<br />
    }</p>
<p>    return $object;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Monotosh</title>
		<link>http://www.lost-in-code.com/programming/php-code/php-array-to-object/comment-page-1/#comment-7354</link>
		<dc:creator>Monotosh</dc:creator>
		<pubDate>Tue, 25 Jan 2011 10:57:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=39#comment-7354</guid>
		<description>Thanks</description>
		<content:encoded><![CDATA[<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cesar</title>
		<link>http://www.lost-in-code.com/programming/php-code/php-array-to-object/comment-page-1/#comment-7297</link>
		<dc:creator>Cesar</dc:creator>
		<pubDate>Fri, 14 Jan 2011 14:42:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=39#comment-7297</guid>
		<description>I have an easier one... working with JSON ;)
$a = array( ... ); //multidimentional array
$b = json_encode($a);

$c = json_decode($b);//-&gt;object
$d = json_decode($b,true);//-&gt;multidimentional array</description>
		<content:encoded><![CDATA[<p>I have an easier one&#8230; working with JSON <img src='http://www.lost-in-code.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
$a = array( &#8230; ); //multidimentional array<br />
$b = json_encode($a);</p>
<p>$c = json_decode($b);//-&gt;object<br />
$d = json_decode($b,true);//-&gt;multidimentional array</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexxandar</title>
		<link>http://www.lost-in-code.com/programming/php-code/php-array-to-object/comment-page-1/#comment-7214</link>
		<dc:creator>Alexxandar</dc:creator>
		<pubDate>Wed, 15 Dec 2010 23:47:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=39#comment-7214</guid>
		<description>Here is my spin at it:
[code]
function recursive_array2object($array)
{
    foreach($array as &amp;$subArray)
    {
        if(is_array($subArray))
        {
            $subArray = recursive_array2object($subArray);
        }
    }
    return (object) $array;

}
[/code]</description>
		<content:encoded><![CDATA[<p>Here is my spin at it:<br />
[code]<br />
function recursive_array2object($array)<br />
{<br />
    foreach($array as &amp;$subArray)<br />
    {<br />
        if(is_array($subArray))<br />
        {<br />
            $subArray = recursive_array2object($subArray);<br />
        }<br />
    }<br />
    return (object) $array;</p>
<p>}<br />
[/code]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael L. Parmley</title>
		<link>http://www.lost-in-code.com/programming/php-code/php-array-to-object/comment-page-1/#comment-7083</link>
		<dc:creator>Michael L. Parmley</dc:creator>
		<pubDate>Mon, 04 Oct 2010 16:19:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=39#comment-7083</guid>
		<description>Add this to deal with numeric arrays

function toObject($array) {
	$obj = new stdClass();
	foreach ($array as $key =&gt; $val) {
		$key = is_numeric($key) ? &#039;num&#039;.$key : $key;
		$obj-&gt;$key = is_array($val) ? toObject($val) : $val;
	}
	return $obj;
}</description>
		<content:encoded><![CDATA[<p>Add this to deal with numeric arrays</p>
<p>function toObject($array) {<br />
	$obj = new stdClass();<br />
	foreach ($array as $key =&gt; $val) {<br />
		$key = is_numeric($key) ? &#8216;num&#8217;.$key : $key;<br />
		$obj-&gt;$key = is_array($val) ? toObject($val) : $val;<br />
	}<br />
	return $obj;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mayoral</title>
		<link>http://www.lost-in-code.com/programming/php-code/php-array-to-object/comment-page-1/#comment-7077</link>
		<dc:creator>Mayoral</dc:creator>
		<pubDate>Mon, 27 Sep 2010 18:16:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=39#comment-7077</guid>
		<description>Example with recursive:

http://www.richardcastera.com/2009/07/06/php-convert-array-to-object-with-stdclass/

Regards!</description>
		<content:encoded><![CDATA[<p>Example with recursive:</p>
<p><a href="http://www.richardcastera.com/2009/07/06/php-convert-array-to-object-with-stdclass/" rel="nofollow">http://www.richardcastera.com/2009/07/06/php-convert-array-to-object-with-stdclass/</a></p>
<p>Regards!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Binod Shukla</title>
		<link>http://www.lost-in-code.com/programming/php-code/php-array-to-object/comment-page-1/#comment-7074</link>
		<dc:creator>Binod Shukla</dc:creator>
		<pubDate>Mon, 27 Sep 2010 07:31:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=39#comment-7074</guid>
		<description>Thanx a lot !
U Rock !!!!!!</description>
		<content:encoded><![CDATA[<p>Thanx a lot !<br />
U Rock !!!!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oyunlar</title>
		<link>http://www.lost-in-code.com/programming/php-code/php-array-to-object/comment-page-1/#comment-7042</link>
		<dc:creator>Oyunlar</dc:creator>
		<pubDate>Sat, 28 Aug 2010 12:48:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=39#comment-7042</guid>
		<description>nice function, thank you..</description>
		<content:encoded><![CDATA[<p>nice function, thank you..</p>
]]></content:encoded>
	</item>
</channel>
</rss>

