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 Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.