php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79312 array_filter should be more improvement
Submitted: 2020-02-27 13:33 UTC Modified: 2020-02-27 14:01 UTC
From: npsingh dot sb at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Filter related
PHP Version: 7.3.15 OS: Window 7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: npsingh dot sb at gmail dot com
New email:
PHP Version: OS:

 

 [2020-02-27 13:33 UTC] npsingh dot sb at gmail dot com
Description:
------------
First, My main concern is FALSE and NULL values not filter function array_filter.

Second, There should be more parameter for array_filter for string and integer type.

Test script:
---------------
$tag_string = 'logo,sky,bird,-0,fire,-1,0,2333,false,logo,FALSE,null,COMPANY,Fire,NULL';

$tag_arr = explode(',', $tag_string );

$tag_arr = array_filter($tag_arr);

print_r($tag_arr);

Expected result:
----------------
Array
(
    [0] => logo
    [1] => sky
    [2] => bird
    [3] => fire
    [4] => 2333
    [5] => logo
    [6] => COMPANY
    [7] => Fire
)

Actual result:
--------------
Array
(
    [0] => logo
    [1] => sky
    [2] => bird
    [3] => -0
    [4] => fire
    [5] => -1
    [7] => 2333
    [8] => false
    [9] => logo
    [10] => FALSE
    [11] => null
    [12] => COMPANY
    [13] => Fire
    [14] => NULL
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-02-27 14:01 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-02-27 14:01 UTC] cmb@php.net
> First, My main concern is FALSE and NULL values not filter
> function array_filter.

Well, that works as it's supposed to, but in your array all
elements are strings (so only an empty string would be filtered
out).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC