当前位置:网站首页>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
?>
边栏推荐
- LeetCode 2310. 个位数字为 K 的整数之和
- Dragonfly low code security tool platform development path
- 数据库内容输出有问题怎么解决
- STM32 standard firmware library function name memory (II)
- 华为面试题: 没有回文串
- C # delay, start the timer in the thread, and obtain the system time
- Slashgear shares 2021 life changing technology products, which are somewhat unexpected
- 求轮廓最大内接圆
- Socket and socket address
- Advanced C language (realize simple address book)
猜你喜欢

CTO如何帮助业务?

大顶堆、小顶堆与堆排序

Thoroughly master prototype__ proto__、 Relationship before constructor (JS prototype, prototype chain)

Kityformula editor configure font size and spacing
![[noi simulation] Elis (greedy, simulation)](/img/a2/f8c8ab3bc8dd779327be3f76990976.png)
[noi simulation] Elis (greedy, simulation)

LeetCode - 搜索二维矩阵

Have you learned the wrong usage of foreach

forEach的错误用法,你都学废了吗

C code audit practice + pre knowledge

Implement a server with multi process concurrency
随机推荐
Kityformula editor configure font size and spacing
fatal: unsafe repository is owned by someone else 的解决方法
OpenCV调用USB摄像头的点滴
Jenkins Pipeline 应用与实践
c语言入门--数组
【apipost】使用教程
大顶堆、小顶堆与堆排序
Tmall product details interface (APP, H5 end)
[development environment] install the visual studio community 2013 development environment (download the installation package of visual studio community 2013 with update 5 version)
一张图彻底掌握prototype、__proto__、constructor之前的关系(JS原型、原型链)
Check password
C RichTextBox controls the maximum number of lines displayed
报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
STM32 standard firmware library function name (I)
Actual combat sharing of shutter screen acquisition
ONNX+TensorRT:将预处理操作写入ONNX并完成TRT部署
Database connection pool and data source
Edit the formula with MathType, and set it to include only mathjax syntax when copying and pasting
Introduction to C language -- array
kityformula-editor 配置字号和间距