views:

65

answers:

2

I am using a multidimensional array and I am trying to use php to find the last value of one of the arrays and based on that last number(value), add one more to it.

Here is my multidimensional array structure:

$_SESSION['cart']['add_complete'][1]['deck_id']

I am trying to create this structure, but instead of where it says 1 now, I want to find out what the last number in the add_complete array is and then add one more to it and put that in the place of the 1. How can I do that?

+1  A: 
$new_num = count( $_SESSION['cart']['add_complete'] ) + 1;
Justin Ethier
This will simply add 1 to the size of the array. I took the question as asking how to add 1 to the *value* of the array.
Bauer
+1  A: 

If you're assigning a value you can also just remove the 1:

$_SESSION['cart']['add_complete'][]['deck_id'] = 'wtv';

... but this is frowned upon some, and I am under the impression it won't be supported in future versions of PHP, so stick with Justin Ethier's answer:

$_SESSION['cart']['add_complete'][count( $_SESSION['cart']['add_complete'] ) + 1]['deck_id']
LeguRi