modcar Posted July 18, 2010 Share Posted July 18, 2010 OK, so I have a php loop with $num += '1'; at the beginning of the loop What Im wanting to do is have variables names according to the number of loops Code I have: $total_to_pay_unrounded = $row['cust_total'] / $num_weeks; $total_to_pay = number_format($total_to_pay_unrounded, 2, '.', ''); I wanting to achieve is: $total_to_pay_unrounded_1 = $row['cust_total'] / $num_weeks; $total_to_pay_1 = number_format($total_to_pay_unrounded_1, 2, '.', ''); $total_to_pay_unrounded_1 = $row['cust_total'] / $num_weeks; $total_to_pay_2 = number_format($total_to_pay_unrounded_2, 2, '.', ''); etc etc Any assistance is appreciated Link to comment https://forums.phpfreaks.com/topic/208078-combining-variables-to-make-another/ Share on other sites More sharing options...
BillyBoB Posted July 18, 2010 Share Posted July 18, 2010 If $num is an integer then it would be $num++ or $num += 1 $num += '1' would create a string '111111...' Link to comment https://forums.phpfreaks.com/topic/208078-combining-variables-to-make-another/#findComment-1087685 Share on other sites More sharing options...
modcar Posted July 18, 2010 Author Share Posted July 18, 2010 its def $num + '1'; I have it on a previous page in a form <td><strong>Vehicle <? echo $num; ?></strong></td> <td> </td> </tr> <tr> <td>Make<span class="formRedStar">*</span></td> <td><input name="car<? echo $num; ?>_make" type="text" id="car<? echo $num; ?>_make" value="<? echo $make; ?>" size="20" /> </td> and the page reads Vehicle 1, Vehicle 2 etc Link to comment https://forums.phpfreaks.com/topic/208078-combining-variables-to-make-another/#findComment-1087701 Share on other sites More sharing options...
isedeasy Posted July 18, 2010 Share Posted July 18, 2010 Use an array rather than variables with incrementing names. Link to comment https://forums.phpfreaks.com/topic/208078-combining-variables-to-make-another/#findComment-1087704 Share on other sites More sharing options...
modcar Posted July 19, 2010 Author Share Posted July 19, 2010 Thats done the trick, thanks!! Link to comment https://forums.phpfreaks.com/topic/208078-combining-variables-to-make-another/#findComment-1088007 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.