Array Exercises and Examples of Arrays using Php
Array is a set of variables that have the same data type and are declared with the same name. Array is an important concept in programming, because the array allows to store data and object reference in large quantities and indexed.
The following is an example example of the use of Array, as follows:
Example:
Example1:
Example2:
Example3: Array Next
Example3: Array prev
Example4: Number of Arrays
Example5: Accessing Arrays In separate variables
Example6: Array With Foreach
Example7: Sort Arrays
Such are examples of the use of arrays, Keep to practice it, Happy coding, and fighting :)
The following is an example example of the use of Array, as follows:
Example:
<?php
$year = array(1924, 2010, 2012, 2024, 2050);
echo $year[3];
?>
Example1:
<?php
$student = array("Eka Haryanto", "Lakilaki", "
11/11/1993 "," B ", 3.41," debageur ");
echo $student[0]. "<br>";
echo $student[1]. "<br>";
echo $student[2]. "<br>";
echo $student[3]. "<br>";
echo $student[4]. "<br>";
echo $student[5]. "<br>";
?>
Example2:
<?php
$student = array("Eka Haryanto", "Lakilaki", "
11/11/1993 "," B ", 3.41," debageur ");
for($x = 0; $x <= 6; $x ++)
{
echo $student[$x]. "<br>";
}
?>
Example3: Array Next
<?php
$student = array("Eka Haryanto", "Lakilaki", "
11/11/1993 "," B ", 3.41," debageur ");
For($x = 0; $x <6; $x ++)
{
echo "Index of student array to:" .key($student). "Contains
".current($student)." <br> ";
sext($student);
}
?>
Example3: Array prev
<?php
$student = array("Eka Haryanto", "Lakilaki", "
11/11/1993 "," B ", 3.41," debageur ");
End($student);
For($x = 0; $x <6; $x ++)
{
echo "The student array index to:" .key($student). "Contains
".current($student)." <br> ";
Prev($student);
}
?>
Example4: Number of Arrays
<?php
$Student = array("Eka Haryanto", "Lakilaki", "
11/11/1993 "," B ", 3.41," debageur ");
$Sumarray = count($student);
echo $sumarray;
?>
Example5: Accessing Arrays In separate variables
<?php
$Student = array("Eka Haryanto", "Lakilaki", "
11/11/1993 "," B ", 3.41," debageur ");
List($name, $sex type, $responder, $points, $IP, $specialization) =
$student;
echo $name. "<br>";
echo $jeniskelamin. "<br>";
echo $respon. "<br>";
echo $points. "<br>";
echo $IP. "<br>";
echo $specialization. "<br>";
?>
Example6: Array With Foreach
<?php
$student = array("Eka Haryanto", "Lakilaki", "
11/11/1993 "," B ", 3.41," debageur ");
foreach($student as $datamahasiswa)
{
echo $datamahasiswa. "<br>";
}
?>
Example7: Sort Arrays
<?php
$Data = array(1,3,2,4,7,8,6,5,9,10);
sort($data);
for($x = 0; $x <= 10; $x ++)
{
echo current($data). "<br>";
next($data);
}
?>
Such are examples of the use of arrays, Keep to practice it, Happy coding, and fighting :)