array_pop()与关键 [英] array_pop() with Key
本文介绍了array_pop()与关键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下阵列
$array = ('fruit' => 'apple',
'vegetable' => 'potato',
'dairy' => 'cheese');
我想用 array_pop ,以获得最后的键/值对
然而,人们会注意到,经过以下
However, one will note that after the following
$last = array_pop($array);
var_dump($last);
这将只输出值(的字符串(6)的奶酪
)
我怎样才能啪从数组,$ P $最后一对pserving键/值阵列结构?
How can I "pop" the last pair from the array, preserving the key/value array structure?
推荐答案
看看 array_slice()
http://php.net/manual/en/function.array-slice.php
print_r(array_slice(array("a" => "1", "b" => 2, "c" => 3), -1, 1));
这篇关于array_pop()与关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文