当前位置:网站首页>php获取数组中键值最大数组项的索引值的方法
php获取数组中键值最大数组项的索引值的方法
2022-07-02 11:56:00 【徊忆羽菲】
一、问题背景
从给定数组中获取值最大的数组项的键值。用途如:获取班级得分最高的学生的姓名。
二、解决方案
<?php
/* * created on 2022-qipa-250 * created by www.qipa250.com */
$arr=array('tom'=>9,'jack'=>3,'kim'=>5,'hack'=>4);
asort($arr);
//print_r($arr);
//输出:array ( [jack] => 3 [hack] => 4 [kim] => 5 [tom] => 9 )
$rel=array();
foreach($arr as $k=>$v){
$rel[]=$k;
}
//echo $rel[0];//输出最小值:jack
echo end($rel);//输出最大值:tom
?>
边栏推荐
- socket(套接字)与socket地址
- fatal: unsafe repository is owned by someone else 的解决方法
- AtCoder Beginner Contest 254
- Wechat applet uses towxml to display formula
- Database connection pool and data source
- Base64 编码原来还可以这么理解
- 传感器数据怎么写入电脑数据库
- C# richTextBox控制显示最大行数
- How does CTO help the business?
- Introduction to C language -- array
猜你喜欢
[email protected] : The platform “win32“ is incompatible with this module."/>info [email protected] : The platform “win32“ is incompatible with this module.

Implement a server with multi process concurrency

Li Chuang EDA learning notes 15: draw border or import border (DXF file)

How does CTO help the business?

【NOI模拟赛】刮痧(动态规划)

Tmall product details interface (APP, H5 end)

Yolov6 training: various problems encountered in training your dataset

mathML转latex

LeetCode 2310. 个位数字为 K 的整数之和

LeetCode 2310. The number of digits is the sum of integers of K
随机推荐
Onnx+tensorrt: write preprocessing operations to onnx and complete TRT deployment
PTA题库 ===>复数四则运算,一帮一,考试座位号(7-73)
Mfc a dialog calls B dialog function and passes parameters
Tmall product details interface (APP, H5 end)
.NET Core 日志系统
Makefile separates file names and suffixes
btrace-(字节码)动态跟踪工具
c语言入门--数组
【apipost】使用教程
Record an error report, solve the experience, rely on repetition
OpenCV调用USB摄像头的点滴
Why can't browsers read JSX?
富文本编辑器添加矢量公式(MathType for TinyMCE ,可视化添加)
【C语音】详解指针进阶和注意点(2)
MFC console printing, pop-up dialog box
Arithmetic operations and related exercises in C language
STM32 standard firmware library function name memory (II)
1. Editing weapon VIM
taobao. logistics. dummy. Send (no logistics delivery processing) interface, Taobao store delivery API interface, Taobao order delivery interface, Taobao R2 interface, Taobao oau2.0 interface
forEach的错误用法,你都学废了吗