1<?php
2/*
3There are 3 Types of array in php
41. Indexed arrays - Arrays with a numeric index
52. Associative arrays - Arrays with named keys
63. Multidimensional arrays - Arrays containing one or more arrays
7
8This is the second one - Associative arrays
9*/
10
11$age = array("Samy"=>"35", "Naveen"=>"37", "Amit"=>"43");
12echo "Mr.Samy is " . $age['Samy'] . " years old.";
13
14?>
1<?php
2 $associativeArray = [
3 "carOne" => "BMW",
4 "carTwo" => "VW",
5 "carThree" => "Mercedes"
6 ];
7
8 echo $associativeArray["carTwo"] . " Is a german brand";
9?>
1<?php
2/*
3There are 3 Types of array in php
41. Indexed arrays - Arrays with a numeric index
52. Associative arrays - Arrays with named keys
63. Multidimensional arrays - Arrays containing one or more arrays
7
8This is the second one - Associative arrays
9*/
10
11$age = array("Samy"=>"35", "Naveen"=>"37", "Amit"=>"43");
12echo "Mr.Samy is " . $age['Peter'] . " years old.";
13
14?>
1<?php
2 /*
3 there are three type of array
4 1 - Indexed array
5 */
6 $a = array('a','b','c');
7 $b = ['a','b','c'];
8 /*
9 2 - Associative array
10 */
11 $c = array(
12 'keyOne'=>'valueOne',
13 'keyTwo'=>'valueTwo'
14 );
15 $d = [
16 'keyOne'=>'valueOne',
17 'keyTwo'=>'valueTwo'
18 ];
19/*
20 3 - Multidimensional array
21 */
22 $c = array(
23 'keyOne'=>array('a','b','c'),
24 'keyTwo'=>array('a'=>'1','b'=>'2')
25 );
26 $d = [
27 'keyOne'=>['a','b','c'],
28 'keyTwo'=>['a'=>'1','b'=>'2']
29 ];
30 ?>
1<?php
2 $array = [
3 'key1' => 'foo',
4 'key2' => 'bar',
5 ];
6 extract($array);
7
8 echo $key1; //print foo
9 echo $key2; //print bar
10?>
1<?php
2$arr = array('fruit' => 'mango', 'vegetable' => 'tomato', 'thing' => 'bag');
3echo $arr['fruit'];
4/*OUTPUT
5mango*/
6?>
7