Documentation Menu

1.5 Template Project

The Joomla! Documentation Working Group is running a project to develop detailed reference and tutorial material on Joomla! 1.5 templates.  There is a project page on the documentation wiki where you can see the work in progress and help us by contributing your knowledge.

Who's Online

We have 5 guests online

Help Site License

The Joomla! Help Site content is copyright © 2005 - 2008 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution NonCommercial ShareAlike 2.5. Some parts of this website may be subject to other licenses.
Home arrow Manual arrow 11. API Reference arrow mosObjectToArray

mosObjectToArray PDF Print E-mail

Last reviewed: 18 Nov 2005, Joomla 1.0.3
phpDocumentor

mosObjectToArray

Copy the contents of an object into an array.

This function traverses each variable in an object and stores it in an array. Objects contained in objects are also converted into an array.

Returns an array containing all the variables in the object if successful. If the parameter passed to it is not an object, it will return null.

Syntax

array mosObjectToArray ( object $obj )

$obj
is the object to be converted to an array.

Defined in

libraries/joomla/functions.php
(includes/joomla.php prior to Joomla 1.1)
(includes/mambo.php prior to Joomla 1.0)

Examples

Example: This function displays the contents of an object as an array.

class exampleA {
    var $red;
    var $orange;
    var $yellow;
}
 
class exampleB {
    var $green;
    var $blue;
    var $violet;
 
    function exampleB() {
        $this->green = 5;
        $this->blue = 7;
        $this->violet = array('a', 'b', 'c');
    }
}
 
function displayObject() {
    $obj1 = new ExampleA();
    
    $obj1->red = 5;
    $obj1->orange = new ExampleB();
    $obj1->yellow = "OK";
 
    $array1 = mosObjectToArray( $obj1 );
 
    foreach ($array1 as $k => $v) {
        echo "$k => $v <br />";
    }
}
 
displayObject();

might produce:

red => 5
orange => Array
yellow => OK 
 

Please report any errors on this page to the Developer Documentation Forum.

Last Updated ( Tuesday, 03 January 2006 )
 
< Prev   Next >