Actions

API16

JArrayHelper/fromObject

From Joomla! Documentation

< API16:JArrayHelper
Revision as of 17:55, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 object to an array

[Edit Descripton]

Description:JArrayHelper/fromObject

Syntax

static fromObject($p_obj, $recurse=true, $regex=null)
Parameter Name Default Value Description
$p_obj The source object
$recurse true True to recurve through multi-level objects
$regex null An optional regular expression to match on field names

Returns

array The array mapped from the given object

Defined in

libraries/joomla/utilities/arrayhelper.php

Importing

jimport( 'joomla.utilities.arrayhelper' );

Source Body

static function fromObject($p_obj, $recurse = true, $regex = null)
{
        $result = null;
        if (is_object($p_obj))
        {
                $result = array();
                foreach (get_object_vars($p_obj) as $k => $v)
                {
                        if ($regex)
                        {
                                if (!preg_match($regex, $k))
                                {
                                        continue;
                                }
                        }
                        if (is_object($v))
                        {
                                if ($recurse)
                                {
                                        $result[$k] = JArrayHelper::fromObject($v, $recurse, $regex);
                                }
                        }
                        else
                        {
                                $result[$k] = $v;
                        }
                }
        }
        return $result;
}

[Edit See Also] SeeAlso:JArrayHelper/fromObject

Examples

<CodeExamplesForm />