[wp-trac] [WordPress Trac] #57136: wp_list_pluck's key argument not working correctly when its zero

WordPress Trac noreply at wordpress.org
Fri Feb 23 02:49:01 UTC 2024


#57136: wp_list_pluck's key argument not working correctly when its zero
-------------------------------------+------------------------------
 Reporter:  dgwatkins                |       Owner:  (none)
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  Awaiting Review
Component:  General                  |     Version:  4.7
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:
-------------------------------------+------------------------------
Description changed by costdev:

Old description:

> This is better explained with an example:
> ```
> wp> var_dump( wp_list_pluck( [ [ 'key1', 'val1' ], [ 'key2', 'val2' ] ],
> 1, 0 ));
> array(2) {
>   [0]=>
>   string(4) "val1"
>   [1]=>
>   string(4) "val2"
> }
> ```
>
> See the missing key?
>
> If we try with array_column it works correctly:
> ```
> wp> var_dump( array_column( [ [ 'key1', 'val1' ], [ 'key2', 'val2' ] ],
> 1, 0 ));
> array(2) {
>   ["key1"]=>
>   string(4) "val1"
>   ["key2"]=>
>   string(4) "val2"
> }
> ```

New description:

 This is better explained with an example:
 {{{
 wp> var_dump( wp_list_pluck( [ [ 'key1', 'val1' ], [ 'key2', 'val2' ] ],
 1, 0 ));
 array(2) {
   [0]=>
   string(4) "val1"
   [1]=>
   string(4) "val2"
 }
 }}}

 See the missing key?

 If we try with array_column it works correctly:
 {{{
 wp> var_dump( array_column( [ [ 'key1', 'val1' ], [ 'key2', 'val2' ] ], 1,
 0 ));
 array(2) {
   ["key1"]=>
   string(4) "val1"
   ["key2"]=>
   string(4) "val2"
 }
 }}}

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57136#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list