You are here: Re: PHP Enumerations? « PHP Programming Language « IT news, forums, messages
Re: PHP Enumerations?

Posted by Ewoud Dronkert on 11/07/05 11:40

Oli Filth wrote:
> Seamus M said the following on 06/11/2005 22:40:
>> I can't find any info on enumerations in the PHP manual
>
> I guess the closest thing you could do (assuming PHP 5) is an abstract
> class with constants, e.g.:
>
> abstract class AllItems
> {
> const Dog = 1;
> const Cat = 2;
> const Ocelot = 3;
> }
>
> echo AllItems::Dog; // displays "1"

Or an associative array perhaps?

$allitems = array('cat' => 1, 'dog' => 2, 'fish' => 3);
echo $allitems['cat'];

Or constants, but they are not restricted to one type or container:

define('ALL_CAT', 1);
define('ALL_DOG', 2);
define('ALL_FISH', 3);
echo ALL_CAT;

--
E. Dronkert

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация