➤ In PHP, you can use the array() construct or [] syntax to define an array. • Indexed array — An array with a numeric key ( index ).
$arr = []; // or $arr = array();
$arr[0] = "Levani";
$arr[1] = "Nika";
$arr[2] = "Giorgi"; // or $arr = ["levani","Nika","Giorgi"]
$arr[] = "Saba"; // add last element in arr
echo "I am $arr[0] \n"; // output: I am Levani
• Associative array — An array where each key has its own specific value. In the following example the array uses keys instead of index numbers:
$ages = [
	"John" => 15,
	"Michael" => 25,
	"Levani" => 19,
	"Mads" => 57
	];
//          or
// $ages["John"] = "15";
// $ages["Michael"] = "25";
// $ages["Levani"] = "19";
// $ages["Mads"] = "57";
echo "I am ".$ages["Levani"]." years old \n"; // output: I am 19 years old
• Multidimensional array — An array containing one or more arrays within itself.
$laptop = [
	"Lenovo" => [
		"price" => 1200,
		"color" => "white",
		"storage" => "300 Gb",
		],
	"Dell" => [
		"price" => 1000,
		"color" => "black",
		"storage" => "500 Gb",
		],
	];
echo "My laptop price is ".$laptop["Dell"]["price"].".\n"; // output: My laptop price is 1000.
by Levani Makhareishvili
2 years ago
PHP
Arrays
1
Pro tip: use ```triple backticks around text``` to write in code fences