1

I am having trouble finding the right function for this.

I have a session array

$_SESSION['cart_items'][0] = (
'item_name'=>'some name',
'item_price'=>'29.99',
...
)

I need to append another array that has a specific key. The array is from a $_POST object.

$_POST['copy'] = array (
'name'=>'my name',
'office'=>'my office'
)

Appended session to look like this.

$_SESSION['cart_items'][0] = (
'item_name'=>'some name',
'item_price'=>'29.99',
...
'copy'=>array(
    'name'=>'my name',
    'office'=>'my office'
    )
)

I tried array push but this gives me an indexed key for the appended array instead of 'copy'

I know the index of the parent array so i could create the new sub array and then loop the $_POST into it but that doesn't seem right either.

3
  • 1
    What do you want the result to look like? Commented Sep 3, 2013 at 15:33
  • last code block of my question... Commented Sep 3, 2013 at 15:34
  • Ah yes, you did say that. Commented Sep 3, 2013 at 15:34

2 Answers 2

4

I might be missing the point - but cant you just do:

$_SESSION['cart_items'][0]['copy'] = $_POST['copy'];
Sign up to request clarification or add additional context in comments.

2 Comments

Or even the code that is written in the question: $_SESSION['cart_items'][0] = ( 'item_name'=>'some name', 'item_price'=>'29.99', 'copy'=>array( 'name'=>'my name', 'office'=>'my office' ) )
Ok, yeah I can do that.
1
$_SESSION['cart_items'][0][$key] = $_POST[$key]; // as you said you know the key .. is it only one?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.