Menentukan nilai minimum dan maximum array dengan PHP
Berikut merupakan contoh kode programnya :
<!DOCTYPE html>
<html>
<head>
<title> Get Maxmin</title>
</head>
<body>
<?php
$array = array (0 =>
array (
'id' => '20110209172713',
'Date' => '2011-02-09',
'Weight' => '200',
),
1 =>
array (
'id' => '20110209172747',
'Date' => '2011-02-09',
'Weight' => '180',
),
2 =>
array (
'id' => '20110209172827',
'Date' => '2011-02-09',
'Weight' => '175',
),
3 =>
array (
'id' => '20110211204433',
'Date' => '2011-02-11',
'Weight' => '195',
),
);
foreach ($array as $key => $value) {
$result[$key] = $value['Weight'];
}
$min = min($result);
$max = max($result);
echo " The array in Minnumum number : ".$min."<br/>";
echo " The array in Maximum number : ".$max."<br/>";
?>
</body>
</html>
<html>
<head>
<title> Get Maxmin</title>
</head>
<body>
<?php
$array = array (0 =>
array (
'id' => '20110209172713',
'Date' => '2011-02-09',
'Weight' => '200',
),
1 =>
array (
'id' => '20110209172747',
'Date' => '2011-02-09',
'Weight' => '180',
),
2 =>
array (
'id' => '20110209172827',
'Date' => '2011-02-09',
'Weight' => '175',
),
3 =>
array (
'id' => '20110211204433',
'Date' => '2011-02-11',
'Weight' => '195',
),
);
foreach ($array as $key => $value) {
$result[$key] = $value['Weight'];
}
$min = min($result);
$max = max($result);
echo " The array in Minnumum number : ".$min."<br/>";
echo " The array in Maximum number : ".$max."<br/>";
?>
</body>
</html>
Hasilnya :
Silahkan mencoba :-)
minmax dengan PHP
Reviewed by ReyGumay
on
November 23, 2016
Rating:
No comments: