1. Create php 09 array 03.html with this content:
a. A form that posts to php 09 array 03.php with this text and these objects:
- DELIMITER Input box with id and name: 'delimiter'
- DATA Input box with id and name: 'delimitedListOfWeights'
- MAX FREE Input box with id and name: 'maxWithOutSurcharge'
- RATE Input box with id and name: 'surchargeFactor'
- Submit button with face GO and id 'go'
b. TEST: Click GO on menubar and it should look like this:
2. Create php 09 array 03.php which does this:
a. Receive the four values posted from php 9 array 03.html
b. Use $delimiter to make an array of $delimitedListOfWeights ($delimitedListOfWeights is a delimited list)
TIPS:
Use explode(...) to make the array. Search e-book for: explode
In JavaScript you used split() to make an array from delimited data. In PHP use explode(...)
c. Using a loop to process all array values and compare each value in list to $maxWithOutSurcharge
If an array value is more than $maxWithOutSurcharge
(1) Compute the amount of array value over $maxWithOutSurcharge
(2) Multiply that amount by $surchargeFactor.
(3) Add result to $total.
TIP: A common mistake is to compare using the array variable and forgetting to compare specific array
values instead of individual array values by using [...].
e. Echo a span with id 'result' that contains the value: $total
3. Example of how to process the data
Assume these values:
delimiter: g
delimitedListOfWeights: 200g345g100g500
maxWithOutSurcharge: 300
surchargeFactor: .1
In this example total would be:
(45 * .1) + (200 * .1) ==> 4.5 + 20 ==> 24.5
Explanation:
345 and 500 are greater than 300.
The amount greater (45 and 200) are multiplied by .1 and added to the total