define ('NAME', 'value of constant'); echo NAME; //output value of constant; echo Name; //output value of constant with somes notice define ('OK', 'its ok', true); echo OK; // output its ok. echo oK; //output its ok, there are no problem here.
Based on PHP Manual we can't define a constant variable with value as array, yes we can't do that.
But we can make a some tricky so a constant can be use as an array with serialize and when we want to used it just reverse with unserialize.
$arr = array ('one'=>'satu', 'two'=>'dua'); // create a constant define ('EN2ID', serialize($arr)); // and we use now foreach (unserialize(EN2ID) as $key => $val) { echo '"', $key, '" in Indonesia is ', $val, "\"\n"; }
Yeah that is not array but string, i dont care.. :)
0 comments:
Post a Comment