note 39191 deleted from function.implode by tomsommer
| From: | tomsommer@php.net | Date: | Tue, 06 Jul 2004 09:15:13 +0000 |
| Subject: | note 39191 deleted from function.implode by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72729@lists.php.net to get a copy of this message | ||
Note Submitter: admin@tenriats.com
----
I often use implode to store arrays as values in my database. Here's a snippet from a script I
wrote where users apply to enter a "clan". The applications are stored in an array located
in one of my database fields.
<?php
if ($step == apply) { // First we explode the value, so the next value is added, instead of the
array being recreated, deleting all previous data stored in it.
$app = explode("!", $iclan[apps]);
// Now we're gonna add another value to the array...
$app[] = "$stat[uname] ($stat[id]) has applied to join $iclan[name]";
// Then use implode() and make the array a string.
implode("!", $app);
// Set it as the field's value.
mysql_query("update clans set apps='$app' where id='$clan'");
}
?>
Then when it comes time to read the applications...
<?php
$app = explode("!", $iclan[apps]);
foreach ($app as $value) { echo $value; }
?>