CAT of PHP Marking Guide
CAT of PHP Marking Guide
Date: 1/03/2024
Duration: 2Hours
Maximum Marks: 40
INSTRUCTIONS:
- Make sure the handwriting is readable and Underline after each question.
1
QUESTION ONE: Choose the correct answer(s). [10Marks]
1. What is the difference between Indexed array and Associative array in PHP?
A. Index array has numeric index while associative array has named keys
B. Index array has numeric index while associative array has named keys
and numeric index both
C. Index array is one-dimensional array with numeric index while
associative array is two-dimensional array with numeric index
D. Index array has numeric index while associative array has one or more
arrays
Answer: A) Index array has numeric index while associative array has
named keys
2. Which PHP function(s) is/are used to compare arrays and returns the
differences?
A. array_diff()
B. array_diff_assoc()
C. array_diff_key()
D. All of the above
A. array_sort()
B. sort()
C. multisort()
D. array_multisort()
Answer: D) array_multisort()
2
5. Which PHP function is used to sort an indexed array in descending order?
A. sort_reverse()
B. reverse_sort()
C. revsort()
D. rsort()
Answer: D) rsort()
A. get()
B. start()
C. current()
D. cur()
Answer: C) current()
A. in_array()
B. check_array()
C. exist()
D. None of the above
Answer: A) in_array()
A. sort()
B. rsort()
C. ksort()
D. krsort()
Answer: D) krsort()
9. Which PHP global variable is used to collect data after submitting an HTML
form?
A. $_GET
B. $_REQUEST
C. $_POST
D. $_ENV
3
Answer: B) $_REQUEST
A. fopen()
B. open()
C. open_file()
D. PHP_open()
Answer: A) fopen()
Answer:
4
Answers:
<?php
$n = 5;
for ($i = 1; $i <= $n; ++$i) {
for ($j = 1; $j <= $i; ++$j) {
echo ' * ';
}
echo '<br>';
}
for ($i = $n; $i >= 1; --$i) {
for ($j = 1; $j <= $i; ++$j) {
echo ' * ';
}
echo '<br> ';
}
?>
5
Answers:
<html>
<body>
for($col=1;$col<=10;$col++)
{
echo "<td>" .($col * $row). "</td>";
}
echo "</tr>";
}
?>
</table>
</body>
</html>
Write a PHP Script to record 10 marks of the students in array then compute it
average and display first five lowest marks of students.
Hint:
Answers:
<?php
$marks= array(78, 60, 62, 68, 71, 68, 73, 85, 66, 64);
$tot_mark = 0;
$array_length = count($marks);
Foreach($marks as $temp)
{
$tot_mark += $temp;
6
}
$avg_marks = $tot_mark/$array_length;
echo "Average marks= ".$avg_marks."<br>";
sort($marks);
echo " List of five lowest marks of student :";
for ($i=0; $i< 5; $i++)
{
echo $marks [$i].", ";
}
?>
Write a PHP Program for finding the biggest number in an array without using
any array functions. Hint: $numbers = array (12,23,45,20,5,6,34,17,9,56,999);
Answers:
<?php
$numbers = array(12,23,45,20,5,6,34,17,9,56,999);
$length = count($numbers);
$max = $numbers[0];
for($i=1;$i<$length;$i++)
{
if($numbers[$i]>$max)
{
$max=$numbers[$i];
}
}
echo "The biggest number is ".$max;
?>
---------------------Good Luck------------------------------------------------------------