0% found this document useful (0 votes)
0 views10 pages

php_programs

The document contains various PHP code snippets demonstrating different data types, operators, control structures, and functions. It covers scalar, array, object, resource, and null data types, along with arithmetic, assignment, comparison, logical, and other operators. Additionally, it includes examples of built-in functions for string manipulation and user-defined functions.

Uploaded by

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

php_programs

The document contains various PHP code snippets demonstrating different data types, operators, control structures, and functions. It covers scalar, array, object, resource, and null data types, along with arithmetic, assignment, comparison, logical, and other operators. Additionally, it includes examples of built-in functions for string manipulation and user-defined functions.

Uploaded by

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

1) Variable.

php
<?php

$n=5;

echo $n."<br>";

$str="Hello PHP";

echo $str;

?>

2) Scalar data type


<?php

$i=10;

$f=10.0;

$str="Hello World";

$b="true";

var_dump($i);

echo "<br>";

var_dump($f);

echo "<br>";

var_dump($str);

echo "<br>";

var_dump($b);

?>
3) Array data type
<?php

$a=array(10,20,30);

print_r($a);

?>

4) Object data type


<?php

class A

function a()

echo "Hii";

$obj=new A();

$obj->a();

?>

5) Resource data type


6) Null data type

7) Arithmetic operator
<?php

$a=10;

$b=5;

$add=$a+$b;
echo "Addition is $add <br>";

$sub=$a-$b;

echo "Subtraction is $sub <br>";

$mul=$a*$b;

echo "Multiplication is $mul <br>";

$div=$a/$b;

echo "Division is $div <br>";

$mod=$a%$b;

echo "Modulus is $mod <br>";

$expo=$a**$b;

echo "Exponent is $expo <br>";

?>

8) Assignment Operator
9) Comparison/Relational Operator
10) Logical Operator
11) Inc/Dec Operator
12) String Operator
13) Array Operator
14) Ternary Operator
15) Spaceship Operator
16) Bitwise Operator

17) Break statement


<?php

for($i=0;$i<=5;$i++)
{

if($i==4)

break;

echo $i."<br>";

?>

18) Continue statement


<?php

for($i=0;$i<=5;$i++)

if($i==4)

continue;

echo $i."<br>";

?>

19) Indexed Array


<?php

$arr=array("apple","banana","mango");

echo "I like $arr[0] and $arr[2]";

?>
20) Associative array
<?php

$arr=array("name"=>"Jay","age"=>20);

echo "Age of $arr[name] is $arr[age]";

?>

21) Multidimensional array


<?php

$arr=array(

array("Jay","Vijay","Ajay"),

array(19,18,20)

);

print_r($arr);

?>

22) Extract() function


<?php

$arr=array("C"=>"Computer","T"=>"Technology");

extract($arr);

echo "C for $C<br>";

echo "T for $T";

?>
23) Compact() function
<?php

$a="Hello";

$b="World";

$c=compact('a','b');

print_r($c)

?>

24) Array_flip() function


<?php

$arr=array("r"=>"red","y"=>"yellow","g"=>"green");

$a=array_flip($arr);

print_r($a);

?>

25) Implode() function


<?php

$arr=array("Hello","PHP","World");

echo implode(" ", $arr);


?>

26) Explode() function


<?php

$str="one,two,three,four,five";

$s=explode(",",$str);

print_r($s);

?>

27) Strlen() function


<?php

$str="Programming World";

echo strlen($str);

?>

28) Str_word_count() function


<?php

$str="Hello my name is jay";

echo str_word_count($str);

?>
29) Strrev() function
<?php

$str="Programming";

echo strrev($str);

?>

30) Strops() function


<?php

$str="Programming world";

echo strpos($str,"world");

?>

31) Str_replace() function


<?php

$arr=array("mango","apple","banana");

print_r(str_replace("apple","grapes",$arr));

?>

32) Strcmp() function


<?php

$str1="Hello";

$str2="Hello";
echo strcmp($str1, $str2);

?>

33) Strtolower() and strtoupper() function


<?php

echo strtolower("HELLO");

echo strtoupper("hello");

?>

34) Ucwords()
<?php

echo ucwords("programming with php");

?>

35) Function
<?php

function greet()

echo "Hello World";

greet();
?>

36) User defined fuction


<?php

function add($a,$b)

$c=$a+$b;

echo "Addition:".$c;

add(10,5);

?>

You might also like