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?>
1function isAssoc(array $arr)
2{
3 if (array() === $arr) return false;
4 return array_keys($arr) !== range(0, count($arr) - 1);
5}
6
7var_dump(isAssoc(['a', 'b', 'c'])); // false
8var_dump(isAssoc(["0" => 'a', "1" => 'b', "2" => 'c'])); // false
9var_dump(isAssoc(["1" => 'a', "0" => 'b', "2" => 'c'])); // true
10var_dump(isAssoc(["a" => 'a', "b" => 'b', "c" => 'c'])); // true
11
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 ?>