What is: Array

An array is a special variable, which can hold more than one value at a time. The array items are indexed with numbers, starting from 0. In PHP we can also index them with strings. These are called associative arrays. An array can contain other arrays as well.

Here is an array example in PHP:

$foods = array('pizza', 'lasagna', 'ravioli');
echo $foods[2]; // outputs ravioli

$foods[] = 'cheeseburger';
echo $foods[3]; // outputs cheeseburger

// associative array
$foods = [
    'fruit' => 'apple',
    'vegetable' => 'paprika'
];
echo $foods['fruit']; // outputs apple

Here is an array example in JavaScript:

var foods = ['pizza', 'lasagna', 'ravioli'];
console.log(foods[2]); // outputs ravioli

foods.push('cheeseburger');
console.log(foods[3]); // outputs cheeseburger

Recent articles

loading
×