|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-12-15 22:29 UTC] pl dot lamballais at flashover dot fr
Description:
------------
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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 08:00:01 2025 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.