PHP Autoincrement Array -
i having trouble expanding php array. here sample of code :
<select name="paymentcounts"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> <?php $arr = array ('client' => "alex", 'billnumber' => "123", 'paymentcounts' => "1", 'amounts' => array ('paymentnumber' => array( array('amount1' => "100.00", 'amountdate1' => "27.05.2015"))), 'activeclient => "1"); echo "<pre>"; print_r($arr); echo "</pre>"; ?>
this how looks when paymentscount 1. can give me approach, if payments count more 1 php array auto expand , more specificly start copying
array('amount1' => "100.00", 'amountdate1' => "27.05.2015"), array('amount2' => "100.00", 'amountdate2' => "27.06.2015")
i think there must combined if, , push_array can't sort out myself. pleased if give me suggestion how make amount$i , amountdate$i index increse 1 until reaches paymentscount
you may consider using for()
, array_push()
function.
schematic code this:
$paymentsarray = array(); $day = "27"; $month = "05"; $year ="2015"; for($i=0; $i <= $paymentcounts; $i++) { array_push($paymentsarray, array('amount1' => "100.00", 'amountdate1' => "$day.$month.$year")); $month++; } $arr = array ('client' => "alex", 'billnumber' => "123", 'paymentcounts' => "1", 'amounts' => $paymentsarray);
Comments
Post a Comment