<?php $arr = [11,18,21,141,811]; $max = $arr[0]; $max_key = 0; foreach( $arr as $key => $value) { if($value > $max) { $max = $value;//哪个最大就赋值给$max $max_key = $key;//最大值,索引赋值 } } echo $max,'索引是:'.$max_key;