Actions

API15

JArrayHelper/toObject

From Joomla! Documentation

< API15:JArrayHelper
Revision as of 11:40, 25 March 2010 by Doxiki (Talk | contribs)

Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Utility function to map an array to a stdClass object.

[Edit Descripton]

Description:JArrayHelper/toObject

Syntax

toObject(&$array, $class= 'stdClass')
Parameter Name Default Value Description
&$array $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

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] SeeAlso:JArrayHelper/toObject

Examples

<CodeExamplesForm />