在CakePhp中组合数组

时间:2014-01-24 08:46:03

标签: php arrays cakephp cakephp-2.0

$new_array_user_id = array('user_id' => $this->Session->read('UserAuth.User.id'));

输出:

Array
(
    [user_id] => 19
)

这里是previos数组代码:

$prevSessionData = $this->Session->read('form.data');
Array
(
    [Project] => Array
        (
            [first_name] => vikas
            [last_name] => tyagi
        )

)

组合数组:

$currentSessionDatas = Hash::merge( (array) $new_array_user_id, $prevSessionData);
Array
(
    [user_id] => 19
    [Project] => Array
        (
            [first_name] => vikas
            [last_name] => tyagi
        )

)

需要输出:

Array
    (

        [Project] => Array
            (    
                [user_id] => 19
                [first_name] => vikas
                [last_name] => tyagi
            )

    )

2 个答案:

答案 0 :(得分:2)

$new_array_user_id = array(
  'Project' => array(
      'user_id' => $this->Session->read('UserAuth.User.id'))
);

答案 1 :(得分:2)

$new_array_user_id['Project']['user_id']=$this->Session->read('UserAuth.User.id');