77. PHP Program to Suppress the Negative elements from the given Array elements.
How does this program work?
- This program is used to suppress the negative elements from the given array elements using PHP.
Here is the code
<html>
<head>
<title>PHP Program To Suppress the negative elements from the given array elements</title>
</head>
<body>
<?php
error_reporting(0); //Initialize array of elements
$a = array(56,-89,62,-84,14,-23 );
$n = count($a);
echo("The Array Elements are: ") ."</br>"; //To print array of elements
foreach( $a as $b )
{
echo $b ." ";
}
for ( $i=0; $i<=$n; $i++)
{
for ($j=$i+1; $j<=$n; $j++)
{
if ( $a[$i] < $a[$j] )
{
$temp = $a[$i] ;
$a[$i] = $a[$j] ;
$a[$j] =$temp ;
}
}
}
echo ("</br> The rearranged array is given below :</br>");
for($i=0; $i<$n; $i++)
{
echo $a[$i]. " ";
}
return 0;
?>
</body>
</html>