HTMLify
Associative-Array.php
Views: 658 | Author: djdj
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <?php //Numeric Array or Index Array $arr = array('ram','shiv','kumar','arjun'); echo $arr[0]; echo $arr[1]; //using array for loop for($i = 0; $i < count($arr); $i++){ echo $arr[$i]. "\n"; } //using array foreach loop foreach ($arr as $naam){ echo $naam. "\n"; } //you can see that both loop has same output and you can use/choose any loop //Associative Array $first = array('aman' => 'abh', 'shubham' => 'shubh', 'khushi' => 'happy', 'tanishka' => 'tanu', 'mohit' => 'o', 7 => 'dj'); //Using this symbol => we associate a value to another value (string) echo $first['aman']. "\n"; echo $first[7]; //Associative array usinf foreach loop foreach ($first as $key => $value) { //where $key is a first value in array echo "\n Short name of $key is $value"; } ?> |