Jump to content

[SOLVED] array_combine() help


djones

Recommended Posts

I need a little help getting the form values combined into an array. I have two fields:

 

<input type="text" name="qty[]" id="qty_'.$i.'" class="qty_input" value="'.$qty.'" />
<input type="hidden" name="cart_id[]" id="cart_id_'.$i.'" value="'.$cart_id.'" />

 

And I need to combine them into an array so I make sure I update the correct quantity with the cart id:

 

$array_qty = array($_POST['qty']);
$array_cart_id = array($_POST['cart_id']);

$qty_cart = array_combine($array_qty, $array_cart_id);

foreach($qty_cart as $qty_u => $cart_id_u){

// DO my update SQL here...

}

print_r($qty_cart);

 

It's not combining them. Any help?

Link to comment
Share on other sites

Hmmm I did what you mentioned and nothing prints:

 

$array_qty = $_POST['qty'];
$array_cart_id = $_POST['cart_id'];

//$qty_cart = array_combine($array_cart_id, $array_qty);

//print_r($qty_cart);
print_r($array_qty);

 

Here are some actual field examples, so there is data there:

 

<input type="text" name="qty[]" id="qty_2" class="qty_input" value="2" />
<input type="hidden" name="cart_id[]" id="cart_id_2" value="116" />

<input type="text" name="qty[]" id="qty_3" class="qty_input" value="1" />
<input type="hidden" name="cart_id[]" id="cart_id_3" value="117" />

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.