-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharray.php
More file actions
56 lines (46 loc) · 1.37 KB
/
array.php
File metadata and controls
56 lines (46 loc) · 1.37 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Topic: Loop
* Author: Muhammad Afzal
* Class: e-Rozgaar Batch#11
* Date: 7th Jan 2021
*/
//Define Constant
define("BR","<br />");
$colors=array("Black","White","Green","Yellow");
echo $colors[0].BR;
echo $colors[1].BR;
echo $colors[2].BR;
echo $colors[3].BR;
//Print the Array Using Loop
for($a=0;$a<4;$a++){
echo $colors[$a].BR;
}
//Define the Array with Custom Index
$fruit[100]="Apple";
$fruit[101]="Orange";
$fruit[102]="Mango";
$fruit[103]="Graps";
echo BR;
//Print the Custom Index Array
for($a=100;$a<104;$a++){
echo $fruit[$a].BR;
}
//Assoc Arrays
$Emp=array("Qasim","Kashif","Abbas","Asif");
$Salary=array("Asif"=>40000,"Qasim"=>20000,"Kashif"=>25000,"Abbas"=>30000);
$Location=array("Qasim"=>"Sargodha","Asif"=>"Islamabad","Kashif"=>"Karachi","Abbas"=>"Lahore");
for($a=0;$a<4;$a++){
$EmpName=$Emp[$a];
echo "Employee Name=".$EmpName." Salary P/M=".$Salary[$EmpName]." Location=".$Location[$EmpName].BR;
}
echo BR;
$GrandSalary=0;
$Counter=1;
foreach($Salary as $name=>$amount){
echo "#".$Counter." ".$name." Takes ".$amount." Salary P/M".BR;
$GrandSalary+=$amount;
$Counter++;
}
echo "Total Salary=".$GrandSalary.BR;
?>