[英]how to unset array key and value?
Array
(
[0] => Array
(
[accountNo] => 208773
)
)
Array
(
[0] => Array
(
[accountNo] => 9415238
)
)
Array
(
)
如何取消設置最后一個數組,使其必須只顯示前2個數組。
請幫忙
謝謝
如果這3個數組是一個數組的內容,那么我們稱之為$array
:
array_pop($array);
將刪除最后一個,並可選擇返回它的值。
array_pop - 從數組末尾彈出元素
http://php.net/manual/function.array-pop.php
這與unset()
的功能相同,但為了好奇,這是另一種方式:
// Move the pointer to the last element
end($array);
// Get the key of the element
$key = key($array);
// Unset the item
unset($array[$key]);
只是使用array_pop()
,另一種方法僅用於娛樂目的,但如果你想改變最后一個元素的值,你可以使用它。
演示: http : //codepad.org/UFjal89X
一些參考:
key()
: http : //php.net/manual/function.key.php
end()
: http : //php.net/manual/function.end.php
試試這個(如果我理解你的問題)
$output =array();
foreach($input as $k=>$v){
if(!empty($v)){
$output[$k]=$v;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.