|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-04-02 15:17 UTC] christian dot krause at metis dot de
exploding and imploding a string (seperated by "+"):
$a = "11+12+13+14+++++++++";
echo ("a befor execution: ".$a."<BR>");
list(
$r["A"],
$r["B"],
$r["C"],
$r["D"],
$r["E"],
$r["F"],
$r["G"],
$r["H"],
$r["I"],
$r["J"],
$r["K"],
$r["L"],
$r["M"]) = explode("+", $a);
$a = implode("+", $r);
echo ("a after execution: ".$a."<BR>");
I expect an output (like PHP 3.0.17):
a befor execution: 11+12+13+14+++++++++
a after execution: 11+12+13+14+++++++++
but the output is (in current version):
a befor execution: 11+12+13+14+++++++++
a after execution: +++++++++14+13+12+11
after execution the string is vis versus. It happens only if I try to implode emty elements. The behaviour is different to PHP 3.0.X
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 14:00:01 2025 UTC |
The result of implode() is in a wrong order, if a "named index" is used. Example exploding and imploding a string (seperated by "+"): $a = "11+12+13+14"; echo ("a befor execution: ".$a."<BR>"); echo ("this works: ".implode("+", explode("+", $a))."<BR>"); list( $r["A"], $r["B"], $r["C"], $r["D"]) = explode("+", $a); echo ("r between execution: ".$r["A"].$r["B"].$r["C"].$r["D"]."<BR>"); $a = implode("+", $r); echo ("a after execution: ".$a."<BR>"); Output: a befor execution: 11+12+13+14 this works: 11+12+13+14 r between execution: 11121314 a after execution: 14+13+12+11 The values in the last row have the wrong order.The problem: list(<a>,<b>) will assign to <b> first, and only then to <a>. This is the case in all versions of PHP 4 (don't know for PHP 3). Usually this assignment order doesn't matter, but in this case it does. (reclassified, analyzed now (was already marked analyzed?)) <?php list($ar['a'],$ar['b']) = array(1,2); var_dump($ar); ?> array(2) { ["b"]=> int(2) ["a"]=> int(1) }