thecodedeveloper.com
thecodedeveloper.com

Reputation: 3240

Combine array In CakePhp

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

Output:

Array
(
    [user_id] => 19
)

Here previos array code:

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

)

Combine array:

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

)

Need Output Like that:

Array
    (

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

    )

Upvotes: 2

Views: 113

Answers (2)

Anubhav
Anubhav

Reputation: 1623

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

Upvotes: 2

cornelb
cornelb

Reputation: 6066

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

Upvotes: 2

Related Questions