php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79997 Completely wrong example output given
Submitted: 2020-08-19 14:41 UTC Modified: 2020-08-19 14:47 UTC
From: yuriy dot naz at mserverone dot com Assigned: cmb (profile)
Status: Not a bug Package: Documentation problem
PHP Version: 7.3.21 OS: Linux
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: yuriy dot naz at mserverone dot com
New email:
PHP Version: OS:

 

 [2020-08-19 14:41 UTC] yuriy dot naz at mserverone dot com
Description:
------------
---
From manual page: https://php.net/function.arsort
---
See "Example #1 arsort() example". Executing this example in the interactive console (php -a) gives completely different result:

php > $fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
php > asort($fruits);
php > foreach ($fruits as $key => $val) {
php {     echo "$key = $val\n";
php { }
c = apple
b = banana
d = lemon
a = orange


1) expected: sorting by key
actual: sorting by value
2) expected: sorting is ascending
actual: sorting is descending

Test script:
---------------
<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
arsort($fruits);
foreach ($fruits as $key => $val) {
    echo "$key = $val\n";
}
?>


Expected result:
----------------
I expect to see this output in the documentation:

c = apple
b = banana
d = lemon
a = orange

Actual result:
--------------
a = orange
d = lemon
b = banana
c = apple

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-08-19 14:47 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-08-19 14:47 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You've used asort() instead of arsort().
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 12:01:31 2024 UTC