Following is program to find minimum number from an array: <?php $numbers=array(12,23,45,20,5,6,34,17,9,56); $length=count($numbers); $min=$numbers[0]; for($i=1;$i<$length;$i++) { if($numbers[$i]<$min) { $min=$numbers[$i]; } } echo "The smallest number is ".$min; ?>
Category: PHP Programs
The simple concept to find fibonacci series is; add two previous term and get next term. Example of Fibonacci Series is; 0 1 1 2 3 5. Following is a program in PHP to print Fibonacci series . 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 <?PHP $first = 0; $second = 1; … Continue reading Fibonacci series
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. Example: <?php $string = "JAVATPOINT"; $length = strlen($string); … Continue reading Reverse String Using PHP
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 0 is always 1. The simplest way to find the factorial of a … Continue reading Factorial Using PHP