当前位置:网站首页>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
?>
边栏推荐
- taobao. trade. Get (get some information of a single transaction), Taobao store order interface, Taobao oauth2.0 interface, Taobao R2 interface code docking and sharing
- Edit the formula with MathType, and set it to include only mathjax syntax when copying and pasting
- Add vector formula in rich text editor (MathType for TinyMCE, visual addition)
- Key points of compilation principle examination in 2021-2022 academic year [overseas Chinese University]
- PTA题库 ===>复数四则运算,一帮一,考试座位号(7-73)
- 报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
- threejs的控制器 立方体空间 基本控制器+惯性控制+飞行控制
- C code audit practice + pre knowledge
- mathML转latex
- STM32 standard firmware library function name (I)
猜你喜欢
obsidian安装第三方插件——无法加载插件
实用调试技巧
taobao. trade. memo. Add (add remarks to a transaction) interface, Taobao store flag insertion interface, Taobao order flag insertion API interface, oauth2.0 interface
fatal: unsafe repository is owned by someone else 的解决方法
Factal: Unsafe repository is owned by someone else Solution
[noi Simulation Competition] scraping (dynamic planning)
实现一个多进程并发的服务器
【NOI模拟赛】刮痧(动态规划)
YoloV6训练:训练自己数据集遇到的各种问题
Makefile separates file names and suffixes
随机推荐
C thread transfer parameters
MFC 控制台打印,弹出对话框
Tmall product details interface (APP, H5 end)
求轮廓最大内接圆
Factal: Unsafe repository is owned by someone else Solution
Check password
记一次报错解决经历依赖重复
871. 最低加油次数 : 简单优先队列(堆)贪心题
obsidian安装第三方插件——无法加载插件
[QNX hypervisor 2.2 user manual]6.3 communication between guest and external
MFC A对话框调用B对话框函数并传参
Bit by bit of OpenCV calling USB camera
[development environment] install the visual studio community 2013 development environment (download the installation package of visual studio community 2013 with update 5 version)
Wechat applet uses towxml to display formula
Fatal: unsafe repository is owned by someone else
LeetCode - 搜索二维矩阵
taobao.trades.sold.get-查询卖家已卖出的交易数据(根据创建时间),淘宝店铺卖出订单查询API接口,淘宝R2接口,淘宝oAuth2.0交易接口代码分享
富文本编辑器添加矢量公式(MathType for TinyMCE ,可视化添加)
mathML转latex
使用mathtype编辑公式,复制粘贴时设置成仅包含mathjax语法的公式