0

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

2 Answers 2

1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.