php - 数组中的下一个键

标签 php arrays

我有一个数组:

$array=array(
    "sdf"=>500,
    "gsda"=>1000,
    "bsdf"=>1500,
    "bads"=>2000,
    "iurt"=>2500,
    "poli"=>3000
);

如何获取下一个 key 的名称?例如,如果当前数组是 gsda,我需要 bsdf

最佳答案

如果指针不在这个元素上,正如其他解决方案假设的那样,您可以使用

<?php
    $keys = array_keys($arr);
    print $keys[array_search("gsda",$keys)+1];

关于php - 数组中的下一个键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7454904/

相关文章:

php - 返回数组中大于X的数字

c++ - 为什么 std::array<int, 10> x 不是零初始化但 std::array<int, 10> x = std::array<int, 10>() 似乎是?

php - 对已分组的结果集进行分组

php - Advanced Rest 客户端中的数据数组响应无效

php - 流交互 As3 -> PHP -> Mysql -> C++

php - ZF2 2 个模块,每个模块都带有路由器主机名

javascript - 如何在Javascript中单击按钮获取随机数组元素

javascript - 比较两个不同长度的数组并返回包含不常见元素的数组

c - 在 C 中打印指向字符串 ( char *arr[ ] ) 的指针数组中的下一个字符串

c++ - 拥有大型二维数组 : static int vs int