API16

API16:JArrayHelper/toObject

From Joomla! Documentation

Revision as of 22:55, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Utility function to map an array to a stdClass object. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JArrayHelper/toObject|Edit D...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Description

Utility function to map an array to a stdClass object.

[Edit Descripton]

Template:Description:JArrayHelper/toObject

Syntax

static toObject(&$array, $class= 'stdClass')
Parameter Name Default Value Description
$array The array to map.
$class 'stdClass' $calss Name of the class to create

Returns

object The object mapped from the given array

Defined in

libraries/joomla/utilities/arrayhelper.php

Importing

jimport( 'joomla.utilities.arrayhelper' );

Source Body

static function toObject(&$array, $class = 'stdClass')
{
        $obj = null;
        if (is_array($array))
        {
                $obj = new $class();
                foreach ($array as $k => $v)
                {
                        if (is_array($v)) {
                                $obj->$k = JArrayHelper::toObject($v, $class);
                        } else {
                                $obj->$k = $v;
                        }
                }
        }
        return $obj;
}

[Edit See Also] Template:SeeAlso:JArrayHelper/toObject

Examples

<CodeExamplesForm />