webCOMAND

cObject::as_array()

Return an associative array where the key is the object field Identifier and the value is the field value.

Only data type (ContentTypeField::is_data_type()) and reference (ContentTypeField::is_reference_type()) fields are included by default, but either can be excluded with the options.

Prototype

array as_array(array $options = [])

Parameters

  • options - associative array of zero or more of the following options.
    • include_data - Include data type fields.  Default is TRUE.
    • include_refs - Include reference fields.  Default is TRUE.

Return

Associative array of field/value pairs.

Example

$repo = \comand::repo();
$contact = $repo->get_first('FROM Contact LIMIT 1');
$fields = $contact->as_array(['include_refs' => FALSE]);
foreach($fields as $field => $value) {
    echo("$field = $value\n");
}