php for array key value

Solutions on MaxInterview for php for array key value by the best coders in the world

showing results for - "php for array key value"
Lilian
11 May 2016
1<?php
2$array = array(1=>"apple",2=>"Orange",3=>"Banana");
3
4foreach($array as $key => $value){
5	echo "The value for " . $key . " is " . $value;
6}
7/*The value for 1 is apple
8The value for 2 is Orange
9The value for 3 is Banana
10
11$array = [1 => "apple", 2 => "Orange", 3 => "Banana"    
12    Is also valid
13];*/  
14?>
Erwan
30 Mar 2018
1$arr = array(
2	'key1' => 'val',
3	'key2' => 'another',
4	'another' => 'more stuff' 
5);
6foreach ($arr as $key => $val){
7	//do stuff
8}
9
10//or alt syntax
11foreach ($arr as $key => $val) :
12   //do stuff here as well
13endforeach;
14