# Field Manual for Hackers

## php array | Find the minimum and maximum set of values. Hint : calculate median

1. This comment has been removed by the author.

2. This comment has been removed by the author.

3. This comment has been removed by the author.

4. This comment has been removed by the author.

5. This comment has been removed by the author.

6. \$arr=array();
\$max=\$arr[0];
\$min=\$arr[0];
for(\$i=0;\$i\$arr[\$i])
{
\$min=\$arr[\$i];
}
}
echo "Maximum:\$max
Minimum:\$min";

7. php
\$k=0;\$l=0;
\$arr=array();
\$max=array();
\$min=array();
if(sizeof(\$arr)%2==0)
{
\$median1= \$arr[sizeof(\$arr)/2];
\$median2=\$arr[(sizeof(\$arr)/2)+1];
\$median=(\$median1+\$median2)/2;
}
else
\$median= \$arr[(sizeof(\$arr)+1)/2];

for(\$i=0;\$i\$median)
{
\$max[\$k]=\$arr[\$i];
\$k++;
}
if(\$arr[\$i]<\$median)
{
\$min[\$l]=\$arr[\$i];
\$l++;
}
}
?>

8. php
\$n=\$_POST['num'];
\$str=\$_POST['arr'];
\$x=explode(',',\$str);
\$sum=0;
for(\$i=0;\$i<\$n;\$i++)
{\$sum=\$sum+\$x[\$i];
}
\$mean=\$sum/\$n;
echo"\$sum and \$mean
";
for(\$i=0;\$i<\$n;\$i++)
{if(\$x[\$i]>\$mean)
{\$max[\$i]=\$x[\$i];
}
else
{\$min[\$i]=\$x[\$i];
}
}
print_r(\$max);
echo"
";
print_r(\$min);
?>

9. \$str=\$_POST['num'];
\$y=explode(",",\$str);
\$n=sizeof(\$y);
\$max=array();
\$min=array();
if(\$n%2==0)
{
\$median1= \$y[\$n/2];
\$median2=\$y[(\$n/2)+1];
\$median=(\$median1+\$median2)/2;
}
else
\$median= \$y[(\$n+1)/2];

\$k=0;
\$p=0;
for(\$i=0;\$i<\$n;\$i++)
{
if(\$y[\$i]>median)
{
\$max[\$p]=\$y[\$i];
\$p++;
}

else
{
\$min[\$k]=\$y[\$i];
\$k++;
}
}