->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
)
Copy items from Array or Object (for form posting) (Previous) check object data, and call objects validation methods. (Next)
Last updated: Tue, 02 Sep 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.