read from multiple defines

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jakobdoppler
Forum Commoner
Posts: 46
Joined: Wed May 21, 2003 6:16 pm

read from multiple defines

Post by jakobdoppler »

mhhhh

i made some defines with a loop

Code: Select all

for ($i=0; $i<5; $i++) &#123;
			define("_PARAM_EMAIL".$i,"email".$i);
		&#125;
but how can i use a loop to read from these defines ? i tried eval and this version. Must be quite simple, but I can't figure it out :-(

Code: Select all

for ($i=0; $i<5; $i++) &#123;
			echo &#123;_PARAM_EMAIL.$i&#125;;
		&#125;
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

constant()
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Or get_defined_constants()

http://us4.php.net/manual/en/function.g ... stants.php

If you're thinking what I think you're thinking (lol), then

Code: Select all

$costants=get_defined_constants();
foreach($constants&#1111;'user'] as $constant)
    &#123; /* do something with your constant here */ &#125;
Cheers,
BDKR
Post Reply