note 39191 added to function.implode
| From: | admin at tenriats dot com | Date: | Tue, 20 Jan 2004 10:14:00 +0000 |
| Subject: | note 39191 added to function.implode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63863@lists.php.net to get a copy of this message | ||
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; }
?>
----
Manual Page -- http://www.php.net/manual/en/function.implode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39191
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39191&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39191&report=yes
Search -- http://master.php.net/manage/user-notes.php