note 22940 modified in function.key by danbrown
| From: | danbrown@php.net | Date: | Sat, 28 Mar 2009 23:11:05 +0000 |
| Subject: | note 22940 modified in function.key by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152567@lists.php.net to get a copy of this message | ||
I'm writing a forum and use an array to hold all the smiles. The keys in the array are the
characters to write to get a smiley, and the data is the filename, like this
$Smiles[':-)'] = 'smile.gif'
To output all the smileys in a table with 3 columns, I wrote this code:
<?php
$the_end = false;
$s = reset($Smiles);
$k = key($Smiles);
while(!$the_end){
echo '<tr>';
for($i=0; $i<3; $i++){
echo '<td>';
if($the_end) echo ' ';
else{
echo $k.'< br><img src="'. $s .'">';
$s = next($Smiles);
if ($s==false) $the_end=true;
else
$k = key($Smiles);
}
echo "</td>\n";
}
echo "</tr>\n";
}
?>
I had to write a space in the < br> tag in the code above, because the board did a line brake
otherwise.
--was--
I'm writing a forum and use an array to hold all the smiles. The keys in the array are the
characters to write to get a smiley, and the data is the filename, like this
$Smiles[':-)'] = 'smile.gif'
To output all the smileys in a table with 3 columns, I wrote this code:
$the_end = false;
$s = reset($Smiles);
$k = key($Smiles);
while(!$the_end){
echo '<tr>';
for($i=0; $i<3; $i++){
echo '<td>';
if($the_end) echo ' ';
else{
echo $k.'< br><img src="'. $s .'">';
$s = next($Smiles);
if ($s==false) $the_end=true;
else
$k = key($Smiles);
}
echo "</td>\n";
}
echo "</tr>\n";
}
I had to write a space in the < br> tag in the code above, because the board did a line brake
otherwise.
http://php.net/manual/en/function.key.php