Explode-update-implode not working

From: Date: Tue, 23 Jun 2009 16:11:16 +0000
Subject: Explode-update-implode not working
Groups: php.general 
Request: Send a blank email to php-general+get-294459@lists.php.net to get a copy of this message
At least not the way I expected it to. Apparently I am doing something wrong, but I can't find anything specific that explains it. This is in PHP 5.2.6. Here is the sequence I am trying to implement without the database portion. (This is typed in since the VNC I am using doesn't support pasting from a Linux client to a MS-Windows server.) ------------------------------------- $buff = "key1|value1~key2|value2"; $lines = explode ("~", $buff); foreach ($lines as $kvpair) { $line = explode ("|", $kvpair); if ($line[0] == "key1") { $line[1] = "value3"; $kvpair = implode ("|", $line); break; } } $newbuff = implode ("~", $lines); ------------------------------------- $kvpair is modified, but that change is ignored by implode() with $newbuff still containing "key1|value1". So why doesn't the change to $kvpair get brought in by implode? What should I do to update that value? Bob McConnell

« previous php.general (#294459) next »