PHP Tutorials

PHP array_intersect() Function 0

PHP array_intersect() Function

Program 1 <html> <body> <center> <pre> <?php // $array1=array(“Mon”,”Tue”,”Wed”,”Sat”); // $array2=array(“Mon”,”Wed”,”Thus”,”Feb”,”Tue”); // $array3=array(“Mon”,”Wed”,”Fri”,”Jan”,”Sat”); // $newarray=array_intersect($array1,$array2,$array3); // print_r($newarray); $array1=array(“x”=>”Mon”,”y”=>”Tue”,”z”=>”Wed”,”k”=>”Sat”); $array2=array(“x”=>”Mon”,”y”=>”Wed”,”z”=>”Thus”,”r”=>”Feb”,”k”=>”Sat”); //$newarray=array_intersect_key($array2,$array1); $newarray=array_intersect_assoc($array1,$array2); print_r($newarray); ?> </pre> </center> </body> </html>

PHP array_map() Function 0

PHP array_map() Function

Program 1 <html> <body> <center> <pre> <?php // function sum($n) // { // return $n+10; // } // function qube($n) // { // return $n*$n*$n; // } // function evenno($n) // { // if($n%2==0)...

PHP array_slice() Function 0

PHP array_slice() Function

Program 1 <html> <body> <center> <pre> <?php // -6 -5 -4 -3 -2 -1 // $myArrray=[“Indore”,”Pune”,”Delhi”,”Mumbai”,”Raipur”,”Banglore”]; // // 0 1 2 3 4 5 // //$newArray=array_slice($myArrray,1,3,true); // //$newArray=array_slice($myArrray,-3,2,true); // $newArray=array_slice($myArrray,-4,3,true); // print_r($newArray); // $myArray=[101=>”Indore”,102=>”Pune”,103=>”Delhi”,104=>”Mumbai”,105=>”Raipur”];...

PHP Array Traversing Method 0

PHP Array Traversing Method

Program 1 <html> <body> <center> <pre> <?php $myArray=[“Indore”,”Data Flair”,”Pune”,”Mumbai”,”Delhi”,”Agra”,”Raipur”,”Dewas”]; // 0 2 3 4 5 6 7 8 end($myArray); for($i=0;$i<count($myArray);$i++) { echo current($myArray).”<br>”; prev($myArray); } // for($i=0;$i<count($myArray);$i++) // { // echo current($myArray).”<br>”; // next($myArray);...

PHP natsort() and array_multisort() Function 0

PHP natsort() and array_multisort() Function

Program 1 <html> <body> <center> <pre> <?php // $myArray=[“Img1.jpg”,”img5.jpg”,”Img3.jpg”,”Img4.jpg”,”img2.jpg”]; // print_r($myArray); // echo “After sorting<br>”; // //natsort($myArray); // natcasesort($myArray); // print_r($myArray); $mycity=[“Indore”,”Agra”,”Delhi”]; $mystate=[“Mp”,”Up”,”Goa”]; print_r($mycity); $newarray=array_reverse($mycity); print_r($newarray); // print_r($mystate); // echo “<br> After Sotring”; //array_multisort($mycity,$mystate);...

Stack Implementation in PHP 0

Stack Implementation in PHP

Program 1 <html> <body> <center> <pre> <?php $mystack=[10,20,30,40,50,60,70,80]; //print_r($mystack); for($i=0;$i<count($mystack);$i++) { echo “<br>”.$mystack[$i]; } // // push // array_push($mystack,50); // echo “<br> After push one element”; // for($i=0;$i<count($mystack);$i++) // { // echo “<br>”.$mystack[$i]; //...

Searching and Sorting using inbuilt Function in PHP 0

Searching and Sorting using inbuilt Function in PHP

Program 1 <html> <body> <center> <pre> <?php // Example of in_array function // $myar=[5,2,20,10,’40’,60,70]; // $n=40; //echo in_array($n,$myar); // if(in_array($n,$myar,true)) // echo “<font color=green size=5>Searching Success</font>”; // else // echo “<font color=red size=5>Searching not...

PHP foreach Loop with Examples 0

PHP foreach Loop with Examples

Program  1 <html> <body> <ul> <pre> <?php $myarray=array(10,25,’67’,89,12,23); foreach($myarray as $data) { echo “<br>”.$data; } //echo in_array(205,$myarray); //echo in_array(67,$myarray,true); //echo array_search(167,$myarray,true); // find max and minvalue from array using foreach //$sum=0; // foreach($myarray as...

Associative Array in PHP 0

Associative Array in PHP

Program 1 <html> <body> <pre> <center> <?php // $myArray=array(10,20,30,40,”vivek”,56.77); // foreach($myArray as $data) // { // echo $data; // } // Asscociative array $myid=array(“id1″=>501,”id2″=>502,”id3″=>503,”id4″=>504); foreach($myid as $key=> $data) { echo “<br>”.$key.”=”.$data; } // //...

Multidimensional Array in PHP 0

Multidimensional Array in PHP

Program 1 <html> <head><title>Array in PHP Application</title> <body> <pre> <center> <?php // $myArray=array( // array(101,”Vishal Sharma”,”MCA”), // array(102,”Amit gupta”,”BTech”), // array(103,”Rohan”,”MBA”), // array(104,”Rajesh”,”MTech”), // array(104,”Dipesh”,”MSc”), // ); // // print_r($myArray); // echo $myArray[0][0].” “;...