|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80522 Conflict in array name with implode
Submitted: 2020-12-15 22:29 UTC Modified: 2020-12-16 00:07 UTC
From: pl dot lamballais at flashover dot fr Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 7.3.25 OS: Lunix Debian
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.
Bug Type:
From: pl dot lamballais at flashover dot fr
New email:
PHP Version: OS:


 [2020-12-15 22:29 UTC] pl dot lamballais at flashover dot fr
1) declare an array
2) use this array as return from a function
3) fill this array manually with values
4) implode the array
The first and second item are swapped in the result string

Test script:
$tab_ret = array();
$tab_ret = myfunction($param);
$data1 = $tab_ret[0];
$data2 = $tab_ret[1];

$tab_ret[0] = "Marcus";
$tab_ret[1] = "John";
$tab_ret[2] = "Peter";
$tab_ret[3] = "Paul";	
$tab_ret[4] = "Ringo";	
$str = implode("-",$tab_ret);
// Result string is John-Marcus-Peter-Paul-Ringo
If rather than using $tab_ret as return from the function you use another array, that's OK.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-16 00:07 UTC]
-Status: Open +Status: Not a bug
 [2020-12-16 00:07 UTC]
function myfunction($param) {
    $tab_ret = array();
    $tab_ret[1] = "One";
    $tab_ret[0] = "Zero";
    return $tab_ret;

implode joins in the order the elements were added to the array - not in order according to their keys.
Fix the function to create [0] before [1], or ksort() the array, or write code to build the string exactly as you want it.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jul 07 02:05:43 2022 UTC