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
2<?php
3$array = array(
4 "foo" => "bar",
5 42 => 24,
6 "multi" => array(
7 "dimensional" => array(
8 "array" => "foo"
9 )
10 )
11);
12
13var_dump($array["foo"]);
14var_dump($array[42]);
15var_dump($array["multi"]["dimensional"]["array"]);
16?>
17
18
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