Hi guys, currently i have this line, that have static value about people name define('NAME', 'john'); PHP: i want it choosing 1 name from this list randomly : john mike jack please help what is the code looks like, will give like for answering
<?php $names = array(1=>'John',2=>'Mike',3=>'Jack'); $names = $names[array_rand($names)]; define('NAME', $names); ?> PHP:
I have a feeling defining a constant for what you are trying to do won't make any sense. Generally a constant should consist of a known value that never changes. Don't use them like a regular variable.
It works but it goes against the standard. This is improper use of a constant. Just use a regular variable to store the name.
There is no need to create the "NAME" constant. The variable $names in the above example holds the value. Using a constant that always changes is bad programming practice. Why are you defining a constant?