[php-src] Issue #12958: `array_walk` with 'ksort' skips the second position of the array.

From: Date: Fri, 15 Dec 2023 14:04:32 +0000
Subject: [php-src] Issue #12958: `array_walk` with 'ksort' skips the second position of the array.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246053@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/12958 Author: jlmobbex ### Description The following code: ```php <?php $a = [ [ 'Field' => 'cache_key', 'Type' => 'varchar(255)', 'Null' => 'NO', 'Key' => 'PRI', 'Default' => null, 'Extra' => '' ], [ 'Field' => 'data', 'Type' => 'text', 'Null' => 'NO', 'Key' => 'PRI', 'Default' => null, 'Extra' => '' ], [ 'Field' => 'date', 'Type' => 'timestamp', 'Null' => 'NO', 'Key' => '', 'Default' => 'current_timestamp()', 'Extra' => '' ], ]; array_walk($a, 'ksort'); print_r($a); ``` Resulted in this output: ``` Array ( [0] => Array ( [Default] => [Extra] => [Field] => cache_key [Key] => PRI [Null] => NO [Type] => varchar(255) ) [1] => Array ( [Field] => data [Type] => text [Null] => NO [Key] => PRI [Default] => [Extra] => ) [2] => Array ( [Default] => current_timestamp() [Extra] => [Field] => date [Key] => [Null] => NO [Type] => timestamp ) ) ``` But I expected this output instead: ``` Array ( [0] => Array ( [Default] => [Extra] => [Field] => cache_key [Key] => PRI [Null] => NO [Type] => varchar(255) ) [1] => Array ( [Default] => [Extra] => [Key] => PRI [Null] => NO [Type] => text [Field] => data ) [2] => Array ( [Default] => current_timestamp() [Extra] => [Field] => date [Key] => [Null] => NO [Type] => timestamp ) ) ``` I didn't find anything on the doc's page that could explain this behavior, which is why I mention it here, but if I'm wrong I apologize for the inconvenience. I was able to replicate the same behavior on all versions after PHP 7.0 using 3v4l.org: https://3v4l.org/e9fLn The behavior is identical when using asort as callback. ### PHP Version PHP > 7.0 ### Operating System _No response_

« previous php.bugs (#246053) next »