doufei1988 2011-07-28 10:23
浏览 30
已采纳

重新格式化数组

In short, I need a way to change:

Array
(
    [CrmOrder] => Array
        (
            [crm_schedule_id] => 59
        )

)

...into this (using PHP)....

Array
(
    [CrmOrder] => Array
        (
            [0] => Array
                (
                    [crm_schedule_id] => 59
                )
        )
)

The reason I need to do this is because I want to use the CakePHP saveAll() function with an array that I'm getting from the Wizard Component. Cake's saveAll needs the data to be one level deeper because CrmOrder belongsTo CrmPerson which hasMany CrmOrder.

As this isn't necessarily a Cake specific question, I'm also adding the 'php' tag to this question.

  • 写回答

4条回答 默认 最新

  • dongma7796 2011-07-28 11:09
    关注

    You should be able to leverage the FormHelper to produce the intended output like so:

    echo $this->Form->input('CrmOrder.0.crm_schedule_id');
    

    (Note the 0 in dot-notation. See second code block on this page in the manual.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 我的数据无法存进链表里
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端