This document serves as a guideline for Assignment Two (3612) and provides detailed explanations.
Please note that by providing this disclosure, I, acknowledge that I am not liable for any marks
awarded to you or any copyright claims resulting from the use of this guideline.
Disclaimer:
While every effort has been made to ensure the accuracy and reliability of the information provided
in this guideline. It is your responsibility to critically evaluate and adapt the information to meet the
specific requirements of your assignment.
QUESTION 1
<?php
//WRITE THE FUNCTION BELOW AS PER THE QUESTION. NO CODE TO INVOKE THE FUNCTION
SHOULD BE INCLUDED HERE
//NO HTML ALLOWED. ONLY PHP CODE IS ALLOWED
function findLongestString(...$strings) {
$maxLength = 0; // Variable to store the length of the longest string
foreach ($strings as $str) {
if (is_string($str)) { // Check if the argument is a string
$length = strlen($str); // Get the length of the string
if ($length > $maxLength) { // Update maxLength if the current string is longer
$maxLength = $length;
}
}
}
return $maxLength;
}
// Test the function
, $strings = array("Test", 123456, "On");
$longestLength = findLongestString(...$strings);
echo $longestLength; // Output: 4
?>
QUESTION 2
<?php
//WRITE THE FUNCTION, INVOKE THE FUNCTION, DISPLAY RESULT BELOW AS PER THE QUESTION.
//NO HTML ALLOWED. ONLY PHP CODE IS ALLOWED
$generateRandomNumbers = function($start, $end, $count) {
$numberRange = range($start, $end); // Create an array of numbers within the range
shuffle($numberRange); // Shuffle the array randomly
return array_slice($numberRange, 0, $count); // Return the desired number of random numbers
};
$randomNums = $generateRandomNumbers(1, 50, 6);
foreach ($randomNums as $num) {
echo $num . " "; // Output each random number separated by a space
}
?>
QUESTION 3
<?php
Please note that by providing this disclosure, I, acknowledge that I am not liable for any marks
awarded to you or any copyright claims resulting from the use of this guideline.
Disclaimer:
While every effort has been made to ensure the accuracy and reliability of the information provided
in this guideline. It is your responsibility to critically evaluate and adapt the information to meet the
specific requirements of your assignment.
QUESTION 1
<?php
//WRITE THE FUNCTION BELOW AS PER THE QUESTION. NO CODE TO INVOKE THE FUNCTION
SHOULD BE INCLUDED HERE
//NO HTML ALLOWED. ONLY PHP CODE IS ALLOWED
function findLongestString(...$strings) {
$maxLength = 0; // Variable to store the length of the longest string
foreach ($strings as $str) {
if (is_string($str)) { // Check if the argument is a string
$length = strlen($str); // Get the length of the string
if ($length > $maxLength) { // Update maxLength if the current string is longer
$maxLength = $length;
}
}
}
return $maxLength;
}
// Test the function
, $strings = array("Test", 123456, "On");
$longestLength = findLongestString(...$strings);
echo $longestLength; // Output: 4
?>
QUESTION 2
<?php
//WRITE THE FUNCTION, INVOKE THE FUNCTION, DISPLAY RESULT BELOW AS PER THE QUESTION.
//NO HTML ALLOWED. ONLY PHP CODE IS ALLOWED
$generateRandomNumbers = function($start, $end, $count) {
$numberRange = range($start, $end); // Create an array of numbers within the range
shuffle($numberRange); // Shuffle the array randomly
return array_slice($numberRange, 0, $count); // Return the desired number of random numbers
};
$randomNums = $generateRandomNumbers(1, 50, 6);
foreach ($randomNums as $num) {
echo $num . " "; // Output each random number separated by a space
}
?>
QUESTION 3
<?php