php - Using array_combine to show user input results -
i'm using array_combine
show results of user choices.
this loop:
<?php if(get_field('sizes')) { ?> <?php while(the_repeater_field('sizes')) { ?> <?php echo the_sub_field('size'); ?> <input type="text" class="quantity" name="quantity[]" value="0"> <input type="hidden" class="productinput" name="product[]" value="<?php echo the_title(); ?> - <?php echo the_sub_field('size'); ?>"> <?php } ?> <?php } ?>
this how i'm outputting results
$quantities = array_combine($_post['product'], $_post['quantity']); foreach ($quantities $product => $quantity) { if ($quantity > 0) { $productresults = "$quantity x $product"; } } echo $productresults;
at moment outputs lastly input quantity , product name. e.g if alter 5 inputs shows 5th.
what missing show inputs changed?
use below code, problem outputing $productresults
after foreach
loop,and because of echoes lastly value assigned.
$productresults = ""; $quantities = array_combine($_post['product'], $_post['quantity']); foreach ($quantities $product => $quantity) { if ($quantity > 0) { $productresults .= "$quantity x $product "; } } echo $productresults;
php arrays
No comments:
Post a Comment