Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

Write a PHP program to illustrate built in Array manipulation functions.(any 6)

 

<?php

$season=array("summer","winter","spring","autumn");

echo "Array is as follows <br>";

foreach( $season as $s )

{

 echo "$s<br />";

}

echo "______________"."<br>";

echo "Length of the array is=".count($season);

echo "<br>______________"."<br>";

echo "Sorted array is as follows <br>";

sort($season);

foreach( $season as $s )

{

 echo "$s<br />";

}

echo "______________"."<br>";

echo "Reverse array is as follows <br>";

$reverseseason=array_reverse($season);

foreach( $reverseseason as $s )

{

 echo "$s<br />";

}

echo "______________"."<br>";

echo "Searching Spring in given array <br>";

$key=array_search("spring",$season);

if($key==1)

{

 echo "Spring Found";

}

else

{

 echo "Spring Not Found";

}

echo "<br>______________"."<br>";

$name1=array("summer","cold","hot","winter");

echo "Array Intersection <br>";

$name3=array_intersect($season,$name1);

foreach( $name3 as $n )

{

 echo "$n<br />";

}

echo "______________"."<br>";

echo "Array Merger <br>";

$name4=array_merge($season,$name1);

foreach( $name4 as $n )

{

 echo "$n<br />";

}

?>

Post a Comment

0 Comments