-1

I'm doing this for school, but am currently stuck with trying to get the array to echo the car in the budget range, but i cant figure out how to do it

so what ive tried doing so far is;

if ((isset($_POST["one"])) && (!empty($_POST["one"]))) {
    $hi = $_POST["one"];
    $arrayName = array('2018 Ford Mustang', '2019 Honda Civic Sedan VTi-L', 'Mazda RX-7', '2018 Honda NSX', 'Jeep Cherokee', 'Jeep Grand Cherokee', '2018 Ford Focus', '2018 Ford Fiesta', 'Nissan patrol ST');
    $arrayprice = array('40000', '31795', '50000', '380000', '44000', '54990', '34490', '20525', '19990');

    foreach ($arrayprice as $key => $value)
    {
        switch ($arrayprice)
        {
            case $hi >= $value: echo "<p>".$arrayName[$key]."</p>"; break;    
            case $hi <= '20000' && $hi >= '30000': echo $arrayName["0"];    

and the same thing, but instead of the zero i had [$key] '0'

if ((isset($_POST["one"])) && (!empty($_POST["one"]))) {
    $hi = $_POST["one"];
    $arrayName = array('2018 Ford Mustang', '2019 Honda Civic Sedan VTi-L', 'Mazda RX-7', '2018 Honda NSX', 'Jeep Cherokee', 'Jeep Grand Cherokee', '2018 Ford Focus', '2018 Ford Fiesta', 'Nissan patrol ST');
    $arrayprice = array('40000', '31795', '50000', '380000', '44000', '54990', '34490', '20525', '19990');

    foreach ($arrayprice as $key => $value)
    {
        switch ($arrayprice)
        {
            case $hi >= $value: echo "<p>".$arrayName[$key]."</p>"; break;
            case $hi <= '20000' && $hi >= '30000': echo $arrayName[$key]'0';

i want it to output the array index that I put in as the car in that budget range. for example if the budget range is between 20000 and 30000 then it should output the ford fiesta, whereas, if the budget is between 10000 and 20000 it should output the nissan patrol st.

(I'm new to programming and all that and just asking for a friend, sorry if you can't understand what I'm trying to say or explain)

treyBake
  • 6,440
  • 6
  • 26
  • 57

2 Answers2

0

Use database and make a table with column names containing this data.

car_model_name, price

you can easily manage those things that you want to make.

Then connect to your table and display the list of all car models then create a condition or statement that will check if the price is in between the $hi price.

It was hard to fix your problem because you don't have any identifier connected to the car_model_name.

Miks Alibo
  • 61
  • 8
0
if (!empty($_POST["one"])) {
$hi = $_POST["one"];
$arrayName = array('2018 Ford Mustang', '2019 Honda Civic Sedan VTi-L', 'Mazda RX-7', '2018 Honda NSX', 'Jeep Cherokee', 'Jeep Grand Cherokee', '2018 Ford Focus', '2018 Ford Fiesta', 'Nissan patrol ST');
$arrayprice = array('40000', '31795', '50000', '380000', '44000', '54990', '34490', '20525', '19990');

$cars_that_fits = []; // every car you can get for your money
$max_fit = 0; // best car for your money
$max_fit_name = '';
foreach ($arrayprice as $key => $value) {
    if ($value < $hi) {
        $cars_that_fits[] = $arrayName[$key];
        if ($max_fit < $hi) { $max_fit = $hi; $max_fit_name = $arrayName[$key]; }
    }
}

}

lukistar
  • 58
  • 1
  • 7