dongnanbi4942 2010-05-19 11:54
浏览 25
已采纳

在PHP中更改数组结构

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条回答 默认 最新

  • douzen1896 2010-05-19 11:57
    关注

    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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥40 图书信息管理系统程序编写
  • ¥15 7-1 jmu-java-m02-使用二维数组存储多元线性方程组
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题