How to find the maximum value in an array in php

零到壹度
Release: 2023-03-22 08:52:01
Original
6995 people have browsed it

This time I will talk to you about how to find the maximum value in an array in php. The following is a practical case, let's take a look.

Without further ado, let’s go straight to the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>php求数组中最大值</title>
<style type="text/css">
 table{
 	width: 980px;
 	border:#000 solid 1px;
 	margin: auto;
 }
 td{
 	border:#000 solid 1px;
 }
</style>
</head>
<body>
<?php 
//求数组中的最大值
$num=array(10,20,35,50,45,32,18);
$max=$num[0];
for($i=1;$i<count($num);$i++){
    if($num[$i]>$max){
        $max=$num[$i];
    }
}
echo &#39;数组中最大的数为:&#39;.$max;

?>
</body>
</html>
Copy after login

Related recommendations:

Get a one-dimensional array in PHP The maximum and minimum values

PHP gets the maximum data in the array value

How to find the maximum value in the array

The above is the detailed content of How to find the maximum value in an array in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!