PHP Array – How to Show Array Value Label

arraydatabasePHPtable

I have an array:

$type = array(
    0 => "Car",
    1 => "SUV",
    2 => "Truck",
    3 => "Bike"
);

When a user selects the options from a form, the associated value is stored in a database.

I want this info to be displayed on another page in a table. Currently it only displays the database saved value (0,1,2,3), but i want it to show as ((Car, SUV, Truck, Bike). How do i do this?

I need a way to make it know that 0=Car, 1=SUV, 2=Truck, 3=Bike.

heres what the table looks like now:
enter image description here

The make column represents the vehicle manufacturer (Toyota, Honda, etc)and type represents (Car, SUV, Truck, Bike).

Best Answer

In the page where you are displaying the data define the array you already defined in the form page i.e,

$type = array(
            0 => "Car",
            1 => "SUV",
            2 => "Truck",
            3 => "Bike"
        );

Now while displaying the column use echo $type[database saved value];

Related Topic