Remove empty array elements

前端 未结 27 4188
半阙折子戏
半阙折子戏 2020-11-21 23:17

Some elements in my array are empty strings based on what the user has submitted. I need to remove those elements. I have this:

foreach($linksArray as $link)         


        
27条回答
  •  天命终不由人
    2020-11-21 23:59

    If you are working with a numerical array and need to re-index the array after removing empty elements, use the array_values function:

    array_values(array_filter($array));
    

    Also see: PHP reindex array?

提交回复
热议问题