Write a PHP code that:
1- |
Creates an array that holds 10 random integer numbers between 1 and 100. |
|
2- |
Moves all multiple of 3-numbers in the array that created in part-a into a new array. |
|
3- |
Moves all multiple of 5-numbers in the array that created in part-a into a new array. |
|
4- |
Find the maximum and the minimum multiple of 3-numbers, if exist. |
|
5- |
Find the maximum and the minimum multiple of 5-numbers, if exist. |
|
6- |
Prints the elements of the created arrays in part-1, part-2 and part-3. |
|
7- |
Prints the maximum and minimum multiple of 3-numbers. |
|
8- |
Prints the maximum and minimum multiple of 5-numbers. |
|
9- |
Prints a suitable message if no multiple of 3-numbers or multiple of 5-numbers are generated. |
PROGRAM::
<!DOCTYPE html>
<html>
<body>
<?php
function displayArray($a){
if(sizeof($a)==0)
{
echo "No elements";
return;
}
foreach (range(0, sizeof($a)-1, 1) as $index) {
echo $a[$index]," ";
}
}
function maxNumber($arr){
if(sizeof($arr)==0)
return 0;
$max=$arr[0];
foreach (range(1, sizeof($arr)-1, 1) as $index) {
if($arr[$index]>$max)
$max=$arr[$index];
}
return $max;
}
function minNumber($arr){
if(sizeof($arr)==0)
return 0;
$max=$arr[0];
foreach (range(1, sizeof($arr)-1, 1) as $index) {
if($arr[$index]<$max)
$max=$arr[$index];
}
return $max;
}
$a = array();
foreach (range(0, 10, 1) as $index) {
$a[$index]=rand(0, 100);
}
echo "Part 1: ";
displayArray($a);
echo "<br>";
$ThreeMulArray = array();
$FiveMulArray = array();
$threeIndex=0;
$fiveIndex=0;
foreach (range(0, 10, 1) as $index) {
if($a[$index]%3==0){
$ThreeMulArray[$threeIndex]=$a[$index];
$threeIndex+=1;
}else if(($a[$index]%5==0)){
$FiveMulArray[$fiveIndex]=$a[$index];
$fiveIndex+=1;
}
unset($a[$index]);
}
echo "Part 2: ";
displayArray($ThreeMulArray);
echo "<br>";
echo "Part 3: ";
displayArray($FiveMulArray);
echo "<br>";
echo "maximum in three multiples array: ";
$result=maxNumber($ThreeMulArray);
if($result)
echo $result;
else
echo "Does not exit";
echo "<br>";
echo "Minimum in three multiples array: ";
$result=minNumber($ThreeMulArray);
if($result)
echo $result;
else
echo "Does not exit";
echo "<br>";
echo "maximum in five multiples array: ";
$result=maxNumber($FiveMulArray);
if($result)
echo $result;
else
echo "Does not exit";
echo "<br>";
echo "Minimum in five multiples array: ";
$result=minNumber($FiveMulArray);
if($result)
echo $result;
else
echo "Does not exit";
?>
</body>
</html>
SCREENSHOTS::
Get Answers For Free
Most questions answered within 1 hours.