更改 PHP 中的数组结构
参考我之前的问题:Show Values in TDropDownList in PRADO。 好吧,我从查询中收到的数组是一个对象数组,例如:
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 ( ) )
如果我将其转换为数组,例如:
Array ( [key 1] => leo [key 2] => ganda )
那么我可以将值填充到 TDropDownList 中。
现在谁能帮我转换我需要的数组结构......?
再次感谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您不关心密钥:
否则:
If you don't care about the keys:
Otherwise:
如果我没记错的话,PHP 中的
foreach
也适用于对象。尝试以下操作:此外,您还可以在 PHP 中以
$object->$propertyName
的形式检索属性。因此,如果您可以获取属性名称,您只需循环遍历它们,检索值并将它们推送到数组中即可。问候
后退2dos
If I remember well,
foreach
in PHP works with objects as well. try the following: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