cheechm Posted August 18, 2008 Share Posted August 18, 2008 How would I add all the values of ${'cost' . $i} ? $num_rows = 3; $i = 0; while ($i < $num_rows) { ${'cost' . $i} = $_POST['cost' . $i]; $i++ } Thanks Link to comment https://forums.phpfreaks.com/topic/120120-solved-adding-values/ Share on other sites More sharing options...
marcus Posted August 18, 2008 Share Posted August 18, 2008 You're probably better off just defining individual variables. $cost1 = $_POST['cost1']; $cost2 = $_POST['cost2']; $cost3 = $_POST['cost3']; Or something like $cost[] = $_POST['cost' . $i]; // inside your while statement echo array_sum($cost); // after your while statement Link to comment https://forums.phpfreaks.com/topic/120120-solved-adding-values/#findComment-618830 Share on other sites More sharing options...
cheechm Posted August 18, 2008 Author Share Posted August 18, 2008 Sorry, $num_rows is usually an undefined value. I get this error though: Fatal error: [] operator not supported for strings (When using the second one) EDIT: Cancel that. All fixed. Thanks! Link to comment https://forums.phpfreaks.com/topic/120120-solved-adding-values/#findComment-618835 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.