itnashvillecom
Account Closed
- Impact
- 1
Let's say that you want to store numerous values within one variable. It may sound complex for some of you, but to those of us that use arrays daily, they are a God send. They help us to unclutter and organize our code and speed up development.
How to create an array:
Now you can use this array.
This will print:
*Note: Do not use quotes in the array when using the numeric key. $cars['2'] is bad. However, you can use $cars['Honda'].
How to create an array:
PHP:
$cars = array(1 => "Chevy", 2=> "Honda", 3=> "Mitsubishi");
Now you can use this array.
PHP:
$cars = array(1 => "Chevy", 2=> "Honda", 3=> "Mitsubishi");
if ($_POST['favorite'] == 2) {
$favorite_car = $cars[2];
echo 'Your favorite make of car is '.$favorite_car;
}
This will print:
Your favorite make of car is Honda
*Note: Do not use quotes in the array when using the numeric key. $cars['2'] is bad. However, you can use $cars['Honda'].