Reverse String10 Mar 2025 | 1 min read A string can be reversed either using strrev() function or simple PHP code. For example, on reversing JAVATPOINT it will become TNIOPTAVAJ. Logic:
Reverse String using strrev() functionA reverse string program using strrev() function is shown. Example: ExampleExecute NowOutput: ![]() Reverse String Without using strrev() functionA reverse string program without using strrev() function is shown. Example: ExampleExecute NowOutput: ![]() Next TopicSwapping two numbers |
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
Prime Number 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. 2 is the only even prime number. It is a natural number greater than 1 and so 0 and 1...
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
Area of Triangle Area of a triangle is calculated by the following Mathematical formula, (base * height) / 2 = Area Area of Triangle in PHP Program to calculate area of triangle with base as 10 and height as 15 is shown. Example: Example <?php $base = 10; $height = 15; echo...
1 min read
Table of Number A table of a number can be printed using a loop in program. Logic: Define the number. Run for loop. Multiply the number with for loop output. Example: We'll print the table of 7. Example <?php define('a', 7); for($i=1; $i<=10; $i++) { echo $i*a; echo '<br>';...
1 min read
Subtracting Two Numbers There are three methods to subtract two numbers: Subtraction in simple code in PHP Subtraction in form in PHP Subtraction without using arithmetic operator (+). Subtraction in Simple Code Subtraction of two numbers 30 and 15 is shown. Example: Example <?php $x=30; $y=15; $z=$x-$y; echo "Difference: ",$z; ?> Execute Now Output: Subtraction in Form By inserting values in the form...
1 min read
Star Triangle The star triangle in PHP is made using for and foreach loop. There are a lot of star patterns. We'll show some of them here. Pattern 1 Example <?php for($i=0;$i<=5;$i++){ for($j=5-$i;$j>=1;$j--){ echo "* "; } echo "<br>"; } ?> Execute Now Output: Pattern 2 Example <?php for($i=0;$i<=5;$i++){ for($j=1;$j<=$i;$j++){ echo "* "; } echo "<br>"; } ?> Execute Now Output: Pattern 3 Example <?php for($i=0;$i<=5;$i++){ for($k=5;$k>=$i;$k--){ echo " "; } for($j=1;$j<=$i;$j++){ echo "* "; } echo "<br>"; } for($i=4;$i>=1;$i--){ for($k=5;$k>=$i;$k--){ echo " "; } for($j=1;$j<=$i;$j++){ echo "* "; } echo "<br>"; } ?> Execute...
1 min read
Alphabet Triangle Method There are three methods to print the alphabets in a triangle or in a pyramid form. range() with for loop chr() with for loop range() with foreach loop Logic: Two for loops are used. First for loop set conditions to print 1 to 5 rows. Second for loop set conditions...
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
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
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