note 31584 added to language.operators.array
| From: | texbungalow at web dot de | Date: | Sat, 26 Apr 2003 23:46:43 +0000 |
| Subject: | note 31584 added to language.operators.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-47157@lists.php.net to get a copy of this message | ||
use '+=' to quickly append an array to another one:
function roman ($nr ) {
$base_digits= array (
1=> "I",
10=> "X",
100=> "C",
1000=> "M",
);
$help_digits= array (
5=> "V",
50=> "L",
500=> "D",
);
$all_digits= $base_digits+ $help_digits;
foreach ($base_digits as $key1=> $value1 )
foreach ($all_digits as $key2=> $value2 )
if ($key1< $key2 )
$segments[$key2- $key1 ]= $value1. $value2;
$segments+= $all_digits;
krsort ($segments );
foreach ($segments as $key=> $value )
while ($key<= $nr ) {
$nr-= $key;
$str.= $value;
}
return $str;
}
echo roman (888); // prints DCCCLXXXVIII
--
http://www.php.net/manual/en/language.operators.array.php
http://master.php.net/manage/user-notes.php?action=edit+31584
http://master.php.net/manage/user-notes.php?action=delete+31584
http://master.php.net/manage/user-notes.php?action=reject+31584