10/12/2012

get the value of more one PHP constants dynamically

using php's constant function

When you define many constants, it is difficult to call them when you use foreach or for clause. Now we may use constant function to realize them.

For example, we define

define('A_1','A');
define('A_2','B');
........
define('A_1000','KKKKKK');


when we use

$a = 88;

echo constant('A_'.$a );

or

for($i=50;$i<70 i="i" p="p">   echo constant('A_'.$i);
}


No comments:

Post a Comment