API16

JArrayHelper/toObject: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
No edit summary
m preparing for archive only
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
Utility function to map an array to a stdClass object.
Utility function to map an array to a stdClass object.


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JArrayHelper/toObject|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JArrayHelper/toObject}}
 
<! removed transcluded page call, red link never existed >


===Syntax===
===Syntax===
Line 55: Line 53:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JArrayHelper/toObject|Edit See Also]]<nowiki>]</nowiki>
<! removed transcluded page call, red link never existed >
</span>
{{SeeAlso:JArrayHelper/toObject}}


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=toObject
  category=toObject
  category=JArrayHelper
  category=JArrayHelper
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>
[[Category:Archived pages API16]]

Latest revision as of 01:19, 25 March 2017

Description

Utility function to map an array to a stdClass object.


<! removed transcluded page call, red link never existed >

Syntax

static 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

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;
}


<! removed transcluded page call, red link never existed >

Examples

Code Examples