I am doing a school practice sac where I have to create a program where the scenario is that:
Penelope is moving house and knows that it will be quite an expensive time. She needs a program that will allow her to add up how much it will cost to furnish each room. She has been creating a text file with the furniture items and prices as she visits online furniture stores.
The solution needs to:
- Enter up to five chosen furniture items and quantities
- See the items she has selected, the quantity required, the price of each item and the total price of all items combined.
(
)So basically I need to create an array using the text file which has the following content:
Dining Table, 595.00
Dining Chair, 145.00
Coffee Table, 259.99
3 Seater Couch, 1200.00
2 Seater Couch, 990.00
Desk, 375.50
Desk Chair, 123.60
Bookshelf- large, 495.99
Bookshelf- small, 298.90
Single Bed, 675.60
Queen Bed, 986.30
I have successfuly done so by making it into an array where the furniture and price are together but are split into different sections as so:
Array ( [0] => Dining Table, 595.00 [1] => Dining Chair, 145.00 [2] => Coffee Table, 259.99 [3] => 3 Seater Couch, 1200.00 [4] => 2 Seater Couch, 990.00 [5] => Desk, 375.50 [6] => Desk Chair, 123.60 [7] => Bookshelf- large, 495.99 [8] => Bookshelf- small, 298.90 [9] => Single Bed, 675.60 [10] => Queen Bed, 986.30 )
However my issue is creating an array from the input. I am aware on how to request and get the input, and I know hwo to validate the input to ensure that the input is correct (no strings in the quantity form, that the variable exists in the array so on). But my concern is to how to assign it so that the first furniture input
(
)is able to be assigned to the correct part of the and array, and to be able to calculate the quantity with the RIGHT furniture, therefore I woul get the total price. I hope my explanation makes sense.
If you wish to see my full code:
Код: Выделить всё
Источник: https://stackoverflow.com/questions/781 ... -price-php
Мобильная версия