|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-11-28 09:57 UTC] bensor987 at neuf dot fr
Description: ------------ Why not add "$var =. 'val';" syntax ? It would concatenate 'val' before $var. Actually, you have to do this <?php $var = 'val' . $var; ?> My suggestion make the code shorter : <?php $var =. 'val'; ?> Test script: --------------- <?php $a = "Hello "; $b = $a . "World!"; // now $b contains "Hello World!" $c = "World! " . $a; // now $c contains "World! Hello " $a = $b = "Hello "; $a .= "World!"; // now $a contains "Hello World!" $b =. "World! "; // now $b contains "World! Hello " ?> PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 14:00:01 2025 UTC |
I think the main concern with "preconcatenation" is 100% chance of reallocation of memory. If it will be part of syntax - people would use it often, but it's something you should avoid using of. Try to execute this code: $c = 10000; $b = 200; $t1 = microtime(1); $str1 = ""; for ($i = 0; $i < $c; ++$i) { $str1 = str_repeat(mt_rand(0, 9), $b) . "\n" . $str1; } $t1 = microtime(1) - $t1; $t2 = microtime(1); $strArr = array(); for ($i = 0; $i < $c; ++$i) { $strArr[] = str_repeat(mt_rand(0, 9), $b); } $strArr = implode("\n", array_reverse($strArr)); $t2 = microtime(1) - $t2; echo $t1 . "\n" . $t2 . "\n"; First part of this code does exactly the same as second part, but it's 300 times slower.