我有一个关联数组:
$users[0] = array('name' => 'Jim', 'depth' => '1', 'bk_id' => '9');
$users[1] = array('name' => 'Jill', 'depth' => '3', 'bk_id' => '10');
$users[2] = array('name' => 'Jack', 'depth' => '7', 'bk_id' => '17');
我想知道一种找到具有最大或最大深度值的数组索引的方法吗?
非常感谢任何建议。
最佳答案
只需迭代并查看最大值:
var max = 0, maxIndex = -1;
for(var i=0;i<users.length;i++) {
if(parseInt(users[i].depth,10) > max) {
max = users[i].depth;
maxIndex = i;
}
}
console.log("Your maximum depth is %d at index %d", max, maxIndex);
关于php - 在关联数组中查找最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9018991/