0% found this document useful (0 votes)
149 views

Practical Assignments For PHP Programming (PART-A)

The document provides 10 examples of PHP scripts with increasing complexity. The scripts demonstrate basic PHP functions like printing text, if/else conditional statements, loops, functions and arrays. Example 9 implements several string functions and example 10 inserts a new item into an array at a given position.

Uploaded by

dishanthpatel242
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
149 views

Practical Assignments For PHP Programming (PART-A)

The document provides 10 examples of PHP scripts with increasing complexity. The scripts demonstrate basic PHP functions like printing text, if/else conditional statements, loops, functions and arrays. Example 9 implements several string functions and example 10 inserts a new item into an array at a given position.

Uploaded by

dishanthpatel242
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical Assignments for PHP Programming

PART-A
1.Write a PHP script to print “hello world”
<?php
echo "Hello World!";
?>

2. Write a PHP script to find odd or even number from given number.
<?php
$num=6;
if($num%2==0)
{
echo "Give Number is EVEN Number";
}
else
{
echo "Give Number is ODD Number";
}
?>

3. Write a PHP script to find maximum of three numbers.


<?php
$a=3;
$b=4;
$c=2;
if($a>$b && $a>$c)
{
echo "A is Biggest Number";
}
else if($b>$c)
{
echo "B is Biggest Number";
}
else
{
echo "C is Biggest Number";
}
?>

4. Write a PHP script to swap two numbers.


<?php
$a=4;
$b=6;
echo "Before Swapping Value of A is $a and Value of B is $b </br>";
$a=$a+$b;
$b=$a-$b;
$a=$a-$b;
echo "After Swapping Value of A is $a and Value of B is $b";
?>
5. Write a PHP script to find the factorial of a number.
<?php
$n=4;
$f=1;
for($i=1;$i<=$n;$i++)
{
$f*=$i;
}
echo "Factorial of the Given Number is $f";
?>

6. Write a PHP script to check whether given number is palindrome or not.


<?php
$num=123;
$rev=0;
$temp=$num;
while($num>1)
{
$r=$num%10;
$rev=$rev*10+$r;
$num=$num/10;
}
if($rev==$temp)
{
echo "The Given Number is Polidrome";
}
else
{
echo "The Give Number is Not a Polidrome";
}
?>

7. Write a PHP script to reverse a given number and calculate its sum
<?php
$num=123;
$rev=0;
$sum=0;
while($num>1)
{
$r=$num%10;
$sum=$sum+$r;
$rev=$rev*10+$r;
$num=$num/10;
}
echo "The Reverse of the Given Number is $rev </br>";
echo " The Sum of its number is $sum";
?>
8. Write a PHP script to generate a Fibonacci series using Recursive function
<?php
$num = 5;
echo "Fibonacci series using recursive function:</br>";
function fibo($num)
{
if($num == 0)
{
return 0;
}
else if( $num == 1)
{
return 1;
}
else
{
return (fibo($num-1) + fibo($num-2));
}
}
for ($i = 0; $i < $num; $i++){
echo fibo($i);
echo "</br>";
}

9. Write a PHP script to implement at least seven string functions.


<?php
$str="hello, good morning students";
$str1=$str;
$str=strtoupper($str);
echo $str."</br>";
$str=strtolower($str);
echo $str."</br>";
$str=ucfirst($str1);
echo $str."</br>";
$str=ucwords($str1);
echo $str."</br>";
$str=strrev($str1);
echo $str."</br>";
$str=strlen($str1);
echo $str."</br>";
$str=lcfirst($str1);
echo $str."</br>";
?>
10. Write a PHP program to insert new item in array on any position in PHP.
<?php
$original_array = array( 2,3,4,4,5,6,7);
echo 'Original array : '."</br>";
foreach ($original_array as $x)
{
echo "$x "."</br>";
}
$ins_value = '9';
$pos = 3;
array_splice( $original_array, $pos, 0, $ins_value );
echo "After inserting 9 in the array is : "."</br>";
foreach ($original_array as $x)
{
echo "$x "."</br>";
}
?>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy