Search code examples
phpmultidimensional-arrayunset

How to unset last item in multidimensional array?


I have a array like below

Array
(
    [0] => Array
        (
            [0] => Date
            [1] => Name
            [2] => Hours
        )
    [1] => Array
        (
            [0] => 2013-01-02
            [1] => Test User
            [2] => 7:59
        )
    [2] => Array
        (
            [0] => 2013-01-03
            [1] => Test User
            [2] => 7:53
        )
    [3] => Array
        (
            [0] => 2013-01-04
            [1] => Test User
            [2] => 8:12
        )
    .
    .
    .
    .
    [16] => Array
    (
        [0] => 
        [1] => Total
        [2] => 103:1
    )
    [17] => Array
        (
            [0] => 
        )
)

And want to remove last item from array, I have tried array_pop but this is not working after passing above array to array_pop gives me output

Array
(
    [0] => 
)

How can I achieve this with minimum code.


Solution

  • Try:

    unset ($array_name[count($array_name)-1]);