当前位置:网站首页>PHP method to get the index value of the array item with the largest key value in the array
PHP method to get the index value of the array item with the largest key value in the array
2022-07-02 15:07:00 【Lingering memory of Yu Fei】
php The method of getting the index value of the array item with the largest key value in the array
One 、 The problem background
Get the key value of the array item with the largest value from the given array . Uses such as : Get the name of the student with the highest score in the class .
Two 、 Solution
<?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);
// Output :array ( [jack] => 3 [hack] => 4 [kim] => 5 [tom] => 9 )
$rel=array();
foreach($arr as $k=>$v){
$rel[]=$k;
}
//echo $rel[0];// Output min :jack
echo end($rel);// Output Max :tom
?>
边栏推荐
- Table responsive layout tips
- LeetCode 209. Minimum length subarray
- 871. 最低加油次数 : 简单优先队列(堆)贪心题
- MFC timer usage
- 使用 TiUP 部署 TiDB 集群
- Simple verification code generator for 51 single chip microcomputer experiment
- Xilinx Vivado set *. svh as SystemVerilog Header
- Find the maximum inscribed circle of the contour
- Mfc a dialog calls B dialog function and passes parameters
- info [email protected]: The platform “win32“ is incompatible with this module.
猜你喜欢
buuctf-pwn write-ups (7)
kityformula-editor 配置字号和间距
学习使用php将时间戳转换为大写日期的方法代码示例
表格响应式布局小技巧
C code audit practice + pre knowledge
Yolov6 training: various problems encountered in training your dataset
编译原理课程实践——实现一个初等函数运算语言的解释器或编译器
Reuse and distribution
Introduction to mathjax (web display of mathematical formulas, vector)
XML配置文件
随机推荐
LeetCode_字符串_简单_412.Fizz Buzz
mathjax 入门(web显示数学公式,矢量的)
为什么只会编程的程序员无法成为优秀的开发者?
2021-2022学年编译原理考试重点[华侨大学]
C# 线程传参
C语言实现N皇后问题
AtCoder Beginner Contest 254
C language exercises - (array)
如何用 Sysbench 测试 TiDB
學習使用php實現公曆農曆轉換的方法代碼
[c voice] explain the advanced pointer and points for attention (2)
MFC 控制台打印,弹出对话框
TiDB数据迁移工具概览
C#延时、在线程中开启定时器、获取系统时间
哈夫曼树:(1)输入各字符及其权值(2)构造哈夫曼树(3)进行哈夫曼编码(4)查找HC[i],得到各字符的哈夫曼编码
Printf function and scanf function in C language
LeetCode_滑动窗口_中等_395.至少有 K 个重复字符的最长子串
The past and present lives of visual page building tools
Onnx+tensorrt: write preprocessing operations to onnx and complete TRT deployment
LeetCode 2310. The number of digits is the sum of integers of K