1.array_keys(end($arr))
$array = array(
‘one‘=>1,
‘two‘=>2,
‘three‘=>3,
‘four‘=>4,
);
$arr = array_keys($array);
var_dump(end($arr));
2.array_pop(end($arr))
$array = array(
‘one‘=>1,
‘two‘=>2,
‘three‘=>3,
‘four‘=>4,
);
$arr = array_keys($array);
var_dump(array_pop($arr));
3.foreach()
$array = array(
‘one‘=>1,
‘two‘=>2,
‘three‘=>3,
‘four‘=>4,
);
foreach($array as $key => $value){
$temp = $key;
}
var_dump($temp)
4.array_slice
$array = array(
‘one‘=>1,
‘two‘=>2,
‘three‘=>3,
‘four‘=>4,
);
$arr = array_slice($array,-1,1,true);
var_dump(key($arr));
时间: 2024-09-08 13:58:36