->toArray()

->toArray() – Get an array of the current result

Synopsis

array $DB_DataObject->toArray ( string $format = '%s' , bool $hideEmpty = false )

Description

Allows the fetching of an associate array (with optional key formating) for use with other packages, like HTML_QuickForm.

From PHP4.2.3RC2 onwards, The values of each column are retrieved using getXXXX() methods so you can change the formating of a row by defining a getter method.

Parameter

  • string $format - a sprintf string eg. 'form[%s]'

  • bool $hideEmpty - If set to true, empty elements (no value/null) will not be returned

Note

This function can not be called statically.

Example

getting arrays

<?php
$person 
= new DataObjects_Person;
$person->get(2);
print_r($person->toArray());
print_r($person->toArray('user[%s]'));
print_r($person->toArray('user[%s]'true));
?>

Sample Output


Array
(
    [id] => 2
    [name] => test
    [username] => username
    [password] =>
    [firstname] => jones
    [lastname] =>
)

Array
(
    [user[id]] => 2
    [user[name]] => test
    [user[username]] => username
    [user[password]] =>
    [user[firstname]] => jones
    [user[lastname]] =>
)

Array
(
    [user[id]] => 2
    [user[name]] => test
    [user[username]] => username
    [user[firstname]] => jones
)