Array
(
[0] => Array
(
[accountNo] => 208773
)
)
Array
(
[0] => Array
(
[accountNo] => 94开发者_高级运维15238
)
)
Array
(
)
how can i unset the last array so that it must display only first 2 array.
please help
thanks
If these 3 arrays are the content of one array, let's call it $array
:
array_pop($array);
Will remove the last one, and optionally return it's value.
array_pop — Pop the element off the end of array
http://php.net/manual/function.array-pop.php
This does the same thing as unset()
here, but for curiosity's sake, here's another way:
// Move the pointer to the last element
end($array);
// Get the key of the element
$key = key($array);
// Unset the item
unset($array[$key]);
Just use array_pop()
though, the other method was for entertainment purposes only, but you could use it if you want to change the last element's value.
Demo: http://codepad.org/UFjal89X
Some reference:
key()
: http://php.net/manual/function.key.php
end()
: http://php.net/manual/function.end.php
try this ( if i understand your problem)
$output =array();
foreach($input as $k=>$v){
if(!empty($v)){
$output[$k]=$v;
}
}
精彩评论