Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize emptying and not zeroing in php array

Shulou Source: shulou.com Published: 2022-06-03 19:51:56 10月04日 Update

This article mainly explains "how to empty and not zero the php array". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "php array how to achieve empty do not go zero" it!

The way to get rid of emptiness and no zeros in the php array is to use strlen as the callback function, which implements code statements such as "array_filter ($array, 'strlen');".

Operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer

How can php array be empty or not zero?

Specific problem description:

I want to delete the NULL,FALSE and''values. I used array_filter, but I also deleted 0.

Is there any way?

Array (NULL,FALSE,'',0,1)-> array (0quotient 1)

Solution:

From http://php.net/manual/en/function.array-filter.php#111091:

If you want to delete NULL,FALSE and empty strings, but leave the value 0, you can use strlen as the callback function:

Array_filter ($array, 'strlen')

At this point, I believe you have a deeper understanding of "how to empty and not zero the php array". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Arrays contents functions methods methods learning practical deeper code interests practicality practicality that is easy to operate more friends versions environment computers empty characters Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Linux Redmi Microsoft Docker