Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete element and also shift the $key in array

Tags:

php

I have an array looks like

Array
(
    [0] => 1213059
    [1] => 1213063
    [2] => 
    [3] => 
    [4] => 1213072
)

I would like to make it as following:

Array
(
    [0] => 1213059
    [1] => 1213063
    [2] => 1213072
)

Is there anyone can help me?

Many thanks

like image 932
Acubi Avatar asked Dec 17 '22 04:12

Acubi


1 Answers

Use array_filter

Check demo here:

array_values(array_filter($your_array)); to keep your keys numerically .

like image 120
Rikesh Avatar answered Jan 10 '23 23:01

Rikesh