Removing parts of a multidimensional array in PHP

Passell

New Member
#1
I have this array $data :
Mã:
Array
(
    [0] => 86086
    [1] => Arnel
    [2] => Paras
)
Array
(
    [0] => 86085
    [1] => Arnely
    [2] => Para
)
Array
(
    [0] =>

)
How do i remove the bottom array that contains no values totally so it only contains :
Mã:
Array
(
    [0] => 86086
    [1] => Arnel
    [2] => Paras
)
Array
(
    [0] => 86085
    [1] => Arnely
    [2] => Para
)
I have tried using array_filter($data, strlen) and it just does this :
Mã:
Array
(

)
 

Admin

Administrator
Thành viên BQT
#2
array_pop() pops and returns the value of the last element of array, shortening the array by one element and will do exactly what you describe. A.

array_shift() does the opposite (removes first element from array and returns the value)

array_pop() on PHP.net

So you can either do:
Mã:
$firstVal = array_pop($data)
or just
Mã:
array_pop($data)
depending on if you want the value back or not.
 

Từ khóa phổ biến

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top