tags:

views:

33

answers:

2

Refers to my previous question : Show values in TDropDownList in PRADO. ok fine the array i receive from query is an object array like :

ContactRecord Object ( [id] => 1 [name] => leo [_recordState:protected] => 1 [_connection:protected] => [_invalidFinderResult:protected] => [_e:TComponent:private] => Array ( ) )
ContactRecord Object ( [id] => 2 [name] => ganda [_recordState:protected] => 1 [_connection:protected] => [_invalidFinderResult:protected] => [_e:TComponent:private] => Array ( ) ) 

If I convert it in to array like:

Array ( [key 1] => leo [key 2] => ganda )

then I can populate values into TDropDownList.

Now can anyone help me to convert array structure which I need ... ?

Again thanks

+1  A: 

If you don't care about the keys:

array_map(function (ContactRecord $o) { return $o->name; }, $origArray)

Otherwise:

$res = array();
foreach ($origArray as $obj) {
    $res[$o->id] = $o->name;
}
Artefacto
A: 

If I remember well, foreach in PHP works with objects as well. try the following:

$ret = array();
foreach ($object as $val) $ret[] = $val;

also, you can retrieve a property in PHP as $object->$propertyName. so if you can get hold of the property names, you just loop through them, retrieve the values and push them to an array.

greetz
back2dos

back2dos