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 this is not your bug, you can add a comment by following this link.
If this is your bug, but 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

Add a Patch

Pull Requests

Add a Pull Request

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: Thu Apr 25 14:01:31 2024 UTC