php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60427 array_reverse docs are slightly misleading
Submitted: 2011-12-01 14:51 UTC Modified: 2011-12-02 13:10 UTC
From: me at andyclyde dot com Assigned: gooh (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: n/a
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: me at andyclyde dot com
New email:
PHP Version: OS:

 

 [2011-12-01 14:51 UTC] me at andyclyde dot com
Description:
------------
The doc page for array_reverse() states that there is a second parameter "preserve_keys". In fact this doesn't seem to have any effect if the array is purely associative whatever you set the second parameter to. This behaviour seems fine but it's not obvious from the docs.

I think this is possibly the same issue as bug #41396.

Test script:
---------------
$array = array( 'one' => 1, 'two' => 2 );
$array = array_reverse( $array, false );

var_dump( $array );

Expected result:
----------------
From the docs you might expect this to return:
array(2) {
  ["one"]=>
  int(2)
  ["two"]=>
  int(1)
}


Actual result:
--------------
array(2) {
  ["two"]=>
  int(2)
  ["one"]=>
  int(1)
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-02 13:00 UTC] gooh@php.net
Automatic comment from SVN on behalf of gooh
Revision: http://svn.php.net/viewvc/?view=revision&revision=320282
Log: fixes Bug #60427: array_reverse docs are slightly misleading
 [2011-12-02 13:05 UTC] gooh@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: gooh
 [2011-12-02 13:05 UTC] gooh@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

I have added clarification that setting preserve_keys will only affect numeric keys. Non-numeric keys are always preserved, regardless of preserve_keys being true of false.
 [2011-12-02 13:10 UTC] me at andyclyde dot com
Great, thanks. Just one thing though, you have a typo in the text you added to the comment (not sure if you c'n'p'ed it or whether it's just an error in your comment:
"regardless of preserve_keys being true of false"
should be
"regardless of preserve_keys being true or false"
 [2011-12-02 13:33 UTC] gooh@php.net
Thanks. It's just in the comments though. The docs will read

If set to &true; numeric keys are preserved.
Non-numeric keys are not affected by this setting and will always be preserved.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 01 01:01:30 2024 UTC