Prime Number10 Mar 2025 | 2 min read A number which is only divisible by 1 and itself is called prime number. Numbers 2, 3, 5, 7, 11, 13, 17, etc. are prime numbers.
Prime number in PHPExample: Here is the Program to list the first 15 prime numbers. ExampleExecute NowOutput: ![]() Prime Number using Form in PHPExample: We'll show a form, which will check whether a number is prime or not. ExampleExecute NowOutput: On entering number 12, we get the following output. It states that 12 is not a prime number. ![]() On entering number 97, we get the following output. It states that 97 is a prime number. ![]() Next TopicTable of Number |
Reverse number A number can be written in reverse order. For example 12345 = 54321 Logic: Declare a variable to store reverse number and initialize it with 0. Multiply the reverse number by 10, add the remainder which comes after dividing the number by 10. Reversing Number in PHP Example: Below progrem shows digits...
1 min read
Alphabet Triangle Pattern Some different alphabet triangle patterns using range() function in PHP are shown below. Pattern 1 Example <?php $alpha = range('A', 'Z'); for($i=0; $i<5; $i++){ for($j=5; $j>$i; $j--){ echo $alpha[$i]; } echo "<br>"; } ?> Execute Now Output: Pattern 2 Example <?php $alpha = range('A', 'Z'); for($i=0;...
1 min read
Tutorial Compiler Programs OOPs Functions Interview Questions | PHP Programming Examples PHP programs are frequently asked in the interview. These programs can be asked from basics, control statements, array, string, oops,...
2 min read
Number Triangle Number triangle in PHP can be printed using for and foreach loop. There are a lot of patterns in number triangle. Some of them are show here. Pattern1 Example <?php $k=1; for($i=0;$i<4;$i++){ for($j=0;$j<=$i;$j++){ echo $k." "; $k++; } echo "<br>"; } ?> Execute Now Output: Pattern 2 Example <?php $k=1; for($i=0;$i<5;$i++){ for($j=0;$j<=$i;$j++){ if($j%2==0) { $k=0; } else { $k=1; } echo $k." "; } echo "<br>"; } ?> Execute Now Output: Pattern 3 Example <?php for($i=0;$i<=5;$i++){ for($j=1;$j<=$i;$j++){ echo $j; } echo "<br>"; } ?> Execute Now Output: Pattern 4 Example <?php for($i=0;$i>=5;$i++){ for($j=1;$j>=$i;$j++){ echo $i; } echo "<br>"; } ?< Execute...
1 min read
Even Odd Program Even numbers are those which are divisible by 2. Numbers like 2,4,6,8,10, etc are even. Odd numbers are those which are not divisible by 2. Numbers Like 1, 3, 5, 7, 9, 11, etc are odd. Logic: Take a number. Divide it by 2. If the remainder is...
1 min read
Fibonacci Series Fibonacci series is the one in which you will get your term by adding ious two numbers. For example, 0 1 1 2 3 5 8 13 21 34 Here, 0 + 1 = 1 ...
1 min read
Factorial Program The factorial of a number n is defined by the product of all the digits from 1 to n (including 1 and n). For example, 4! = 4*3*2*1 = 24 6! = 6*5*4*3*2*1 = 720 Note: It is denoted by n! and is calculated only for positive integers. Factorial of...
2 min read
Reverse String A string can be reversed either using strrev() function or simple PHP code. For example, on reversing JAVATPOINT it will become TNIOPTAVAJ. Logic: Assign the string to a variable. Calculate length of the string. Declare variable to hold reverse string. Run for loop. Concatenate string inside for loop. Display reversed string. Reverse String...
1 min read
Leap Year Program A leap year is the one which has 366 days in a year. A leap year comes after every four years. Hence a leap year is always a multiple of four. For example, 2016, 2020, 2024, etc are leap years. Leap Year Program This program states...
2 min read
Armstrong Number An Armstrong number is the one whose value is equal to the sum of the cubes of its digits. 0, 1, 153, 371, 407, 471, etc are Armstrong numbers. For example, 407 = (4*4*4) + (0*0*0) + (7*7*7) = 64...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India