Forum Moderators: coopster

Message Too Old, No Replies

constants and whats not allowed.

constants

         

Matthew1980

6:20 pm on Jun 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there people of webmaster world,

Just a quick ask:-

$SETTING_ARRAY = array();
$SETTING_ARRAY['on_off'] = "0";// set to 1 or 0 depending on what you want to come first..

define(CONSTANT_NAME, $SETTING_ARRAY['on_off']);

IS it possible to have the boolean part of this set from an array? Because as it is (with different names..) it doesnt seem to set the constant to either 1 or 0 when i set it through the array, yet the print_r function clearly shows the value is set.

Thanks,

Matthew

dreamcatcher

10:12 pm on Jun 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Matthew,

What are you trying to accomplish? Constants must always be quoted when being set:

define('CONSTANT_NAME', $SETTING_ARRAY['on_off']);

or else you`ll receive a error that the constant isn`t set, but assumed.

echo CONSTANT_NAME;

Will now return 0 as expected.

dc

Matthew1980

10:33 am on Jun 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi DC,

Data retrieval from db, assigning boolean values to constants to act as switches, ie display different sets of buttons (user/admin), footer text display on/off. At least thats how i thought I could achieve it.

Cheers,

Matthew

dreamcatcher

12:42 pm on Jun 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Matthew,

Why not just use the variable itself from the database? Use an enum field to set between two states. Maybe 'yes' & 'no'. And then use that value to determine what to display. Can`t see the advantage of re-assigning the value elsewhere?

Unless I`m missing something?

dc