Site icon T4Tutorials.com

Finding the Highest Lowest value in an array – PHP MySQL

Finding the Highest Lowest value in an array – PHP MySQL

In this tutorial, we will cover the highest and lowest value program in PHP and MySQL.

Finding the highest lowest value in an array using while loop

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" 
content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>



</body>
</html>
<?php
$t4_mtx = array  
  (  
  array(1,8,4),  
  array(2,9,5),  
  array(3,6,10)  
  );  
  
$i = 0;
while($i < 3) {  
 $j = 0;
 while($j < 3) {  
    echo $t4_mtx[$i][$j]." ";
	$j++;
  }  
  echo "<br>";
  $i++;  
}
$t4_high=$t4_mtx[0][0];
$t4_low=$t4_mtx[0][0];

$i=0;
while($i<3)
{
$j=0;
while($j<3)
{
if($t4_mtx[$i][$j] > $t4_high)
$t4_high=$t4_mtx[$i][$j];
$j++;
}
$i++;
}

$i=0;
while($i<3)
{
$j=0;
while($j<3)
{
if($t4_mtx[$i][$j] < $t4_low)
$t4_low=$t4_mtx[$i][$j];
$j++;
}
$i++;
}

echo "Highest value=".$t4_high;
echo "<br/>";
echo "lowest value=".$t4_low;  
?> 

Output

Finding the highest lowest value in an array using do while loop

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>



</body>
</html>
<?php
$t4_mtx = array  
  (  
  array(1,8,4),  
  array(2,9,5),  
  array(3,6,10)  
  );  
  
$i = 0;
do
 {  
 $j = 0;
 while($j < 3) {  
    echo $t4_mtx[$i][$j]." ";
	$j++;
  }  
  echo "<br>";
  $i++;  
}while($i < 3);
$t4_high=$t4_mtx[0][0];
$t4_low=$t4_mtx[0][0];

$i=0;
Do
{
$j=0;
Do
{
if($t4_mtx[$i][$j] > $t4_high)
$t4_high=$t4_mtx[$i][$j];
$j++;
}while($j<3);
$i++;
}while($i<3);

$i=0;
Do
{
$j=0;
Do
{
if($t4_mtx[$i][$j] < $t4_low)
$t4_low=$t4_mtx[$i][$j];
$j++;
}while($j<3);
$i++;
}while($i<3);

echo "Highest value=".$t4_high;
echo "<br/>";
echo "lowest value=".$t4_low;  
?> 

Finding the highest Lowest value in an array value entered by the user using while loop

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; 
charset=iso-8859-1" />
<title>Untitled Document</title>
<style>
input[type="text"] {
    width: 20px;
	height: 20px;
}
</style>
</head>

<body>
<form method ="Post">

Matrix <br>
<input type="text" name="1">
<input type="text" name="2">
<input type="text" name="3"><br>
<input type="text" name="4">
<input type="text" name="5">
<input type="text" name="6"><br>
<input type="text" name="7">
<input type="text" name="8">
<input type="text" name="9"><br>
<input type ="submit" name="ins" value="Insert">

</form>
</body>
</html>
<?php
$t4_mtx = array(array(3), array(3));
if (isset($_POST['ins']))
{
$t4_mtx[0][0]=$_POST['1'];
$t4_mtx[0][1]=$_POST['2'];
$t4_mtx[0][2]=$_POST['3'];
$t4_mtx[1][0]=$_POST['4'];
$t4_mtx[1][1]=$_POST['5'];
$t4_mtx[1][2]=$_POST['6'];
$t4_mtx[2][0]=$_POST['7'];
$t4_mtx[2][1]=$_POST['8'];
$t4_mtx[2][2]=$_POST['9'];

$i = 0;
while($i < 3) {  
 $j = 0;
 while($j < 3) {  
    echo $t4_mtx[$i][$j]." ";
	$j++;
  }  
  echo "<br>";
  $i++;  
}

$t4_low=$t4_mtx[0][0];
$t4_high=$t4_mtx[0][0];
$i=0;
while($i<3)
{
$j=0;
while($j<3)
{
if($t4_mtx[$i][$j] > $t4_high)
$t4_high=$t4_mtx[$i][$j];
$j++;
}
$i++;
}

$i=0;
while($i<3)
{
$j=0;
while($j<3)
{
if($t4_mtx[$i][$j] < $t4_low)
$t4_low=$t4_mtx[$i][$j];
$j++;
}
$i++;
}

echo "Highest value=".$t4_high;
echo "<br/>";
echo "lowest value=".$t4_low; 

}  
?>

Output

Finding the highest Lowest value in an array value entered by the user using do while loop

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style>
input[type="text"] {
    width: 20px;
	height: 20px;
}
</style>
</head>

<body>
<form method ="Post">

Matrix <br>
<input type="text" name="1">
<input type="text" name="2">
<input type="text" name="3"><br>
<input type="text" name="4">
<input type="text" name="5">
<input type="text" name="6"><br>
<input type="text" name="7">
<input type="text" name="8">
<input type="text" name="9"><br>
<input type ="submit" name="ins" value="Insert">

</form>
</body>
</html>
<?php
$t4_mtx = array(array(3), array(3));
if (isset($_POST['ins']))
{
$t4_mtx[0][0]=$_POST['1'];
$t4_mtx[0][1]=$_POST['2'];
$t4_mtx[0][2]=$_POST['3'];
$t4_mtx[1][0]=$_POST['4'];
$t4_mtx[1][1]=$_POST['5'];
$t4_mtx[1][2]=$_POST['6'];
$t4_mtx[2][0]=$_POST['7'];
$t4_mtx[2][1]=$_POST['8'];
$t4_mtx[2][2]=$_POST['9'];

$i = 0;
Do {  
 $j = 0;
 Do {  
    echo $t4_mtx[$i][$j]." ";
	$j++;
  }while($j < 3);  
  echo "<br>";
  $i++;  
}while($i < 3);

$t4_low=$t4_mtx[0][0];
$t4_high=$t4_mtx[0][0];
$i=0;
Do
{
$j=0;
Do
{
if($t4_mtx[$i][$j] > $t4_high)
$t4_high=$t4_mtx[$i][$j];
$j++;
}while($j<3);
$i++;
}while($i<3);

$i=0;
while($i<3)
{
$j=0;
while($j<3)
{
if($t4_mtx[$i][$j] < $t4_low)
$t4_low=$t4_mtx[$i][$j];
$j++;
}
$i++;
}

echo "Highest value=".$t4_high;
echo "<br/>";
echo "lowest value=".$t4_low; 

}  
?> 

 

Exit mobile version