Tools, FAQ, Tutorials:
Getting Minimum/Maximum Value of an Array in PHP
How To Get the Minimum or Maximum Value of an Array in PHP?
✍: FYIcenter.com
If you want to get the minimum or maximum value of an array, you can use the min() or max() function. Here is a PHP script on how to use min() and max():
<?php
$array = array(5, 7, 6, 2, 1, 3, 4, 2);
print("Minimum number: ".min($array)."\n");
print("Maximum number: ".max($array)."\n");
$array = array("Zero"=>"PHP", "One"=>"Perl", "Two"=>"Java");
print("Minimum string: ".min($array)."\n");
print("Maximum string: ".max($array)."\n");
?>
This script will print:
Minimum number: 1 Maximum number: 7 Minimum string: Java Maximum string: Perl
As you can see, min() and max() work for string values too.
⇒ Creating Your Own Functions in PHP
⇐ Splitting a String into an Array in PHP
2016-12-28, ∼8172🔥, 0💬
Popular Posts:
How To Access a Global Variable inside a Function? in PHP? By default, global variables are not acce...
What is EPUB 2.0 Metadata "dc:creator" and "dc:contributor" elements? EPUB 2.0 Metadata "dc:creator"...
How to convert a JSON text string to an XML document with PHP language? Currently, there is no built...
Why I am getting "The Windows SDK version 8.1 was not found" error, when building my C++ application...
How to use the "set-variable" Policy Statement to create custom variables for an Azure API service o...