PHP fill up multidimensional associative array - easiest way -
i want use $_session
store items in cart. items defined id
, each item has 3 sizes , each size there stored item's quantity. use multidimensional associative array that
$_session['cart']['id'.$_get['id']]['size'.$_post['size']]['quantity'] += $_post['quantity'];
but guess problem getting (notice: undefined index
) because arrays not defined first.
i keep simple, easiest way?
your issue you're assuming items set in $_session
. need assume aren't , start adding them in.
you'd harness isset()
.
if(!isset($_session['cart']['id'.$_get['id']])) { $_session['cart']['id'.$_get['id']] = array( 'sizeone' => array( 'quantity' => 0 ), 'sizetwo' => array( 'quantity' => 0 ), 'sizethree' => array( 'quantity' => 0 ), ); }
you'd modify above set product id require run through same sort of isset()
add selected sizes. i'm showing how create initial structure array.
Comments
Post a Comment