Input:
<?php
$a = array(5,3,6,10,12);
echo $a[0]; // Basic array
?>
Output: 5
Input:
<?php
$a = array(5,3,6,10,12);
echo count($a); // Array length
?>
Output: 6
Input:
<?php
$a = array(5,3,6,10,12,14);
$total = count($a);
for($i=0; $i<$total; $i++){ // Array values print by for loop
echo $a[$i];
echo "<br/>";
}
?>
Output:
5
3
6
10
12
14
Input:
<?php
$details = array("Animash"=>"21", "Dulal"=>"22", "Jit"=>"21", "Shobuj"=>"22" );
foreach($details as $a => $b){ // Associative array
echo "Name = ".$a.", Age = ".$b;
echo "<br/>";
}
?>
Output:
Name = Animash, Age = 21
Name = Dulal, Age = 22
Name = Jit, Age = 21
Name = Shobuj, Age = 22
Input:
<?php
$informations = array( // Multidimensional arrays
array("Animash", "Dulal", "Jit", "Shobuj"),
array("Ismail", "Sadequl", "Sohel", "Kasmeri"),
array("Hemonta", "Monjila", "Parul", "Aivy")
);
echo $informations[0][1];
?>
Output: Dulal
Input:
<?php
$informations = array( // Multidimensional arrays
array("Animash", "Dulal", "Jit", "Shobuj"),
array("Ismail", "Sadequl", "Sohel", "Kasmeri"),
array("Hemonta", "Monjila", "Parul", "Aivy"),
array("Mamun", "Sojib", "Shoriful", "Opu")
);
for($i=0;$i<4;$i++){
echo "<p>$i Number Array Values</p>";
echo "<ul>";
for($j=0;$j<4;$j++){
echo "<li>".$informations[$i][$j]."</li>";
}
echo "</ul>";
}
?>
Output:
0 Number Array Values
1 Number Array Values
2 Number Array Values
3 Number Array Values
Input:
<?php
$Students = array("Animash", "Dulal", "Jit", "Shobuj", "Ismail", "Sadequl", "Sohel", "Kasmeri");
$numbers = array(5,9,1,10,2,11,6,3);
sort($Students); // Sequence Sorting Strings
sort($numbers); // Sequence Sorting Integers
$length = count($Students);
$num_length = count($numbers);
for($i=0;$i<$length;$i++){
echo $Students[$i];
echo " ";
}
echo "<br/>";
for($i=0;$i<$num_length;$i++){
echo $numbers[$i];
echo " ";
}
?>
Output:
Animash Dulal Ismail Jit Kasmeri Sadequl Shobuj Sohel
1 2 3 5 6 9 10 11
Input:
<?php
$Students = array("Animash", "Dulal", "Jit", "Shobuj", "Ismail", "Sadequl", "Sohel", "Kasmeri");
$numbers = array(5,9,1,10,2,11,6,3);
rsort($Students); // Reverse Sorting Strings
rsort($numbers); // Reverse Sorting Integers
$length = count($Students);
$num_length = count($numbers);
for($i=0;$i<$length;$i++){
echo $Students[$i];
echo " ";
}
echo "<br/>";
for($i=0;$i<$num_length;$i++){
echo $numbers[$i];
echo " ";
}
?>
Output:
Sohel Shobuj Sadequl Kasmeri Jit Ismail Dulal Animash
11 10 9 6 5 3 2 1
<?php
$a = array(5,3,6,10,12);
echo $a[0]; // Basic array
?>
Output: 5
Input:
<?php
$a = array(5,3,6,10,12);
echo count($a); // Array length
?>
Output: 6
Input:
<?php
$a = array(5,3,6,10,12,14);
$total = count($a);
for($i=0; $i<$total; $i++){ // Array values print by for loop
echo $a[$i];
echo "<br/>";
}
?>
Output:
5
3
6
10
12
14
Input:
<?php
$details = array("Animash"=>"21", "Dulal"=>"22", "Jit"=>"21", "Shobuj"=>"22" );
foreach($details as $a => $b){ // Associative array
echo "Name = ".$a.", Age = ".$b;
echo "<br/>";
}
?>
Output:
Name = Animash, Age = 21
Name = Dulal, Age = 22
Name = Jit, Age = 21
Name = Shobuj, Age = 22
Input:
<?php
$informations = array( // Multidimensional arrays
array("Animash", "Dulal", "Jit", "Shobuj"),
array("Ismail", "Sadequl", "Sohel", "Kasmeri"),
array("Hemonta", "Monjila", "Parul", "Aivy")
);
echo $informations[0][1];
?>
Output: Dulal
Input:
<?php
$informations = array( // Multidimensional arrays
array("Animash", "Dulal", "Jit", "Shobuj"),
array("Ismail", "Sadequl", "Sohel", "Kasmeri"),
array("Hemonta", "Monjila", "Parul", "Aivy"),
array("Mamun", "Sojib", "Shoriful", "Opu")
);
for($i=0;$i<4;$i++){
echo "<p>$i Number Array Values</p>";
echo "<ul>";
for($j=0;$j<4;$j++){
echo "<li>".$informations[$i][$j]."</li>";
}
echo "</ul>";
}
?>
Output:
0 Number Array Values
- Animash
- Dulal
- Jit
- Shobuj
1 Number Array Values
- Ismail
- Sadequl
- Sohel
- Kasmeri
2 Number Array Values
- Hemonta
- Monjila
- Parul
- Aivy
3 Number Array Values
- Mamun
- Sojib
- Shoriful
- Opu
Input:
<?php
$Students = array("Animash", "Dulal", "Jit", "Shobuj", "Ismail", "Sadequl", "Sohel", "Kasmeri");
$numbers = array(5,9,1,10,2,11,6,3);
sort($Students); // Sequence Sorting Strings
sort($numbers); // Sequence Sorting Integers
$length = count($Students);
$num_length = count($numbers);
for($i=0;$i<$length;$i++){
echo $Students[$i];
echo " ";
}
echo "<br/>";
for($i=0;$i<$num_length;$i++){
echo $numbers[$i];
echo " ";
}
?>
Output:
Animash Dulal Ismail Jit Kasmeri Sadequl Shobuj Sohel
1 2 3 5 6 9 10 11
Input:
<?php
$Students = array("Animash", "Dulal", "Jit", "Shobuj", "Ismail", "Sadequl", "Sohel", "Kasmeri");
$numbers = array(5,9,1,10,2,11,6,3);
rsort($Students); // Reverse Sorting Strings
rsort($numbers); // Reverse Sorting Integers
$length = count($Students);
$num_length = count($numbers);
for($i=0;$i<$length;$i++){
echo $Students[$i];
echo " ";
}
echo "<br/>";
for($i=0;$i<$num_length;$i++){
echo $numbers[$i];
echo " ";
}
?>
Output:
Sohel Shobuj Sadequl Kasmeri Jit Ismail Dulal Animash
11 10 9 6 5 3 2 1
No comments:
Post a Comment