1. Print Hello World using php
<?php
echo "hello world";
?>
<?php
$a = 5;
$b = 6;
$c = 5;
$d = 2;
$e = 9;
echo $a + $b + $c + $d + $e;
?>
<?php
$a = 5;
$b = 10;
echo "addition is ", $a + $b,"<br>";
echo "multiplication is ", $a * $b,"<br>";
echo "division is ", $a / $b, "<br>";
echo "substraction is ", $a - $b ,"<br>";
?>
<?php
$r = 5;
$pi = 3.14;
$a = $pi *($r*$r);
echo "area of circle is ", $a;
?>
<?php
$base = 10;
$height = 15;
echo "Area of triangle ",($base * $height)/2 ;
?>
<?php
$width = 20;
$length = 10;
echo "area of rectangle is ". $width * $length;
?>
<?php
$sub1 = 70;
$sub2 = 80;
$sub3 = 90;
$sub4 = 95;
$sub5 = 85;
$total = $sub1 + $sub2 + $sub3 + $sub4 + $sub5;
echo "percentage is ", $total / 500 * 100;
?>
<?php
$a = 2;
if($a % 2 == 0){
echo "no is odd";
}else{
echo "no is even";
}
?>
<?php
$a = -5;
if($a < 0){
echo "no is negative";
}else{
echo "no is positive";
}
?>
<?php
$num = 14597;
$sum=0; $rem=0;
for ($i =0; $i<=strlen($num);$i++) {
$rem=$num%10;
$sum = $sum + $rem;
$num=$num/10;
}
echo "Sum of digits 14597 is $sum";
?>
<?php
$count = 0;
$num = 2;
while ($count < 15 )
{
$div_count=0;
for ( $i=1; $i<=$num; $i++)
{
if (($num%$i)==0)
{
$div_count++;
}
}
if ($div_count<3)
{
echo $num." , ";
$count=$count+1;
}
$num=$num+1;
}
?>
<?php
// Function to check if a number is perfect
function isPerfectNumber($N)
{
// To store the sum
$sum = 0;
// Traversing through each number
// In the range [1,N)
for ($i = 1; $i < $N; $i++)
{
if ($N % $i == 0)
{
$sum = $sum + $i;
}
}
// returns True is sum is equal
// to the original number.
return $sum == $N;
}
// Driver's code
$N = 6;
if (isPerfectNumber($N))
echo " Perfect Number";
else
echo "Not Perfect Number";
?>
php
define('a', 7);
for($i=1; $i<=10; $i++)
<?{
echo $i*a;
echo '<br>';
}
?>
<?php
$num = 4;
$factorial = 1;
for ($x=$num; $x>=1; $x--)
{
$factorial = $factorial * $x;
}
echo "Factorial of $num is $factorial";
?>
<?php
$num=407;
$total=0;
$x=$num;
while($x!=0)
{
$rem=$x%10;
$total=$total+$rem*$rem*$rem;
$x=$x/10;
}
if($num==$total)
{
echo "Yes it is an Armstrong number";
}
else
{
echo "No it is not an armstrong number";
}
?>
<?php
function palindrome($n){
$number = $n;
$sum = 0;
while(floor($number)) {
$rem = $number % 10;
$sum = $sum * 10 + $rem;
$number = $number/10;
}
return $sum;
}
$input = 1235321;
$num = palindrome($input);
if($input==$num){
echo "$input is a Palindrome number";
} else {
echo "$input is not a Palindrome";
}
?>
<?php
$num = 23456;
$revnum = 0;
while ($num > 1)
{
$rem = $num % 10;
$revnum = ($revnum * 10) + $rem;
$num = ($num / 10);
}
echo "Reverse number of 23456 is: $revnum";
?>
<?php
$string = "JAVATPOINT";
echo "Reverse string of $string is " .strrev ( $string );
?>
<?php
$a = 45;
$b = 78;
// Swapping Logic
$third = $a;
$a = $b;
$b = $third;
echo "After swapping:<br><br>";
echo "a =".$a." b=".$b;
?>
<?php
function isLeap($year)
{
return (date('L', mktime(0, 0, 0, 1, 1, $year))==1);
}
//For testing
for($year=1991; $year<2016; $year++)
{
If (isLeap($year))
{
echo "$year : LEAP YEAR<br />\n";
}
else
{
echo "$year : Not leap year<br />\n";
}
}
?>
<?php
for($i=0;$i<=5;$i++){
for($j=1;$j<=$i;$j++){
echo "* ";
}
echo "<br>";
}
?>
<?php
// PHP program to print all
// the values of an array
// given array
$array = array("Geek1", "Geek2",
"Geek3", "1", "2","3");
// Loop through array
foreach($array as $item){
echo $item . "\n";
}
?>
php
$ele = array("Ryan", "Ahana", "Ritvik", "Amaya");
$no_of_ele = count($ele);
echo "Number of elements present in the array: ".$no_of_ele;
?>
<?php
$cars = array("Volvo", "BMW", "Toyota");
sort($cars);
?>
<?php
$cars = array("Volvo", "BMW", "Toyota");
rsort($cars);
?>
<?php
$a=array(5,15,25);
echo array_sum($a);
?>
<?php
echo(max(44,16,81,12));
?>
<?php
echo(min(22,14,68,18,15) . "<br>");
?>
Comments
Post a Comment