1. What is the factorial of 5?
The factorial of a number is the product of all positive integers up to that number. So 5 factorial equals 5 × 4 × 3 × 2 × 1, which is 120.
Get the Preplance app for a seamless learning experience. Practice offline, get daily streaks, and stay ahead with real-time interview updates.
Get it on
Google Play
4.9/5 Rating on Store
PHP · Question Set
Common Interview Coding Challenges (PHP) interview questions for placements and exams.
Questions
15
Included in this set
Subject
PHP
Explore more sets
Difficulty
Mixed
Level of this set
Go through each question and its explanation. Use this set as a focused practice pack for PHP.
The factorial of a number is the product of all positive integers up to that number. So 5 factorial equals 5 × 4 × 3 × 2 × 1, which is 120.
For complete preparation, combine this set with full subject-wise practice for PHP. You can also explore other subjects and sets from the links below.
Each number in the Fibonacci sequence is the sum of the two preceding ones. After 5 comes 8 (3 + 5).
You can split the string into an array of words, reverse the array, and join it back into a string. This rearranges word order rather than individual letters.
$words = explode(' ', $str); echo implode(' ', array_reverse($words));A palindrome check can be done by comparing the string with its reversed version. If both are equal, the string is a palindrome.
if($str == strrev($str)) echo 'Palindrome';
The sort function arranges array elements in ascending order by value while reindexing the array numerically.
sort($arr);
The modulus operator (%) checks the remainder of division. If number % 2 equals zero, the number is even; otherwise, it's odd.
if($num % 2 == 0) echo 'Even';
The strrev function reverses the order of characters in a string and returns the reversed string.
echo strrev('Hello'); // olleHThe count function returns the total number of elements in an array or the number of properties in an object.
count([1,2,3,4]); // 4
A palindrome string remains the same when reversed, such as level or madam. Checking this is a common PHP coding test question.
The array_sum function adds up all numeric elements of an array and returns the total.
array_sum([2,4,6]); // 12
You can use array_unique to remove duplicate entries. It keeps only the first occurrence of each value and returns a new array with unique elements.
$unique = array_unique($arr);
PHP provides str_word_count to count how many words exist in a given string. This is often used for text analysis and content length checks.
str_word_count('Hello world!');You can use the built-in functions max and min to quickly retrieve the highest and lowest values in an array without manually looping through the data.
max($arr); min($arr);
The array_diff function compares two or more arrays and returns values from the first array that are not present in the others.
array_diff($arr1,$arr2);
You can use nested loops. The outer loop controls rows, and the inner loop prints spaces and stars in each row, creating a pyramid shape. This tests logical thinking and loop control understanding.