I think that I have an easy questions, but I'm unable to find what I'm looking wrong!!
I've an array where there are some strings:
$tipus_membre = array("lider","colider","vetera","membre");
and this strings are defined:
define("LIDER","Leader");
define("COLIDER","Co-leader");
define("VETERA","Elder");
define("MEMBRE","Member");
I'm trying to print in a form but i'm unable to get it. With this first option i get only the name "lider", "colider"....:
<select name="cla_tipus" required>
<?php
for($i=0;$i<count($tipus_clan);$i++){
echo '<option value="'.$i.'">'.$tipus_membre[$i].'</option>';
}
?>
</select>
and if i put:
constant($tipus_clan[$i]);
I get nothing.
(Edited the $var)
Thanks to all for the quick answers, finally the problem was where you said, in the case-sensitive.
The code now it works with a minor change and it's:
<?php
for($i=0;$i<count($tipus_clan);$i++){
echo '<option value="'.$i.'">'.constant(strtoupper($tipus_membre[$i])).'</option>';
}
?>
Constants are case-sensitive, maybe try making your array all uppercase, you can use
strtoupper()
function to capitalize
This should work for you:
<?php
define("LIDER", "Leader");
define("COLIDER", "Co-leader");
define("VETERA", "Elder");
define("MEMBRE", "Member");
$tipus_membre = array(LIDER, COLIDER, VETERA, MEMBRE);
?>
<select name="cla_tipus" required>
<?php
foreach($tipus_membre as $k => $v)
echo "<option value='" . $v . "'>" . $tipus_membre[$k] . "</option>";
?>
</select>
Multiple issues with your code
for($i=0;$i<count($tipus_clan);$i++){
echo '<option value="'.$i.'">'.$tipus_clan[$i].'</option>';
}
You actually define $tipus_membre above, and then you use $tipus_clan in the for loop... which doesn't exist. Change the above to
for($i=0;$i<count($tipus_membre);$i++){
echo '<option value="'.$i.'">'.$tipus_membre[$i].'</option>';
}
Also, constant() is case sensitive; You'll want to define everything in $tipus_membre in uppercase (or convert them to uppercase when calling constant())for the defined constants to be grabbed, otherwise you'll get an undefined warning.