this is the code i have
variable that I bring from the database $profile['image'];<--- in this variable I can bring several options for example:
presentable,aseado
presentable,aseado,De traje
Presentable,aseado,uniforme
so if for example the variable brings presentable,neat in the option I would like to do a if($perfil['imagen'] == 'presentable'){ //codigo}
something similar to this if you could give me an example
$perfil['imagen'];
<option if($perfil['imagen'] == 'presentable'){ echo "selected";} value="presentable">Presentable</option>
<option if($perfil['imagen'] == 'aseado'){ echo "selected";} value="aseado">Aseado</option>
<option if($perfil['imagen'] == 'traje'){ echo "selected";} value="traje">Traje</option>
<option if($perfil['imagen'] == 'condicion saludable'){ echo "selected";} value="condicion saludable">Condicion saludable</option>
<option if($perfil['imagen'] == 'sin tatuajes'){ } value="sin tatuajes">Sin tatuajes</option>
<option if($perfil['imagen'] == 'sin percing'){ } value="sin percing">Sin percing</option>
<option if($perfil['imagen'] == 'sin expansiones'){ } value="sin expansiones">Sin expansiones</option>
I would like something similar to this to validate if the value of the variable $profil['experience'] that comes from the database is equal to any of the option values
It is an example that I did but the variable $profil['experiencia'](6 months) only brought a value
$perfil['experiencia'] == "6 meses"
<option <?php if($perfil['experiencia'] == "6 meses"){ echo "selected"; } ?> value="6 meses">6 meses</option>
<option <?php if($perfil['experiencia'] == "1 año"){ echo "selected"; } ?> value="1 año">1 año</option>
<option <?php if($perfil['experiencia'] == "2 años"){ echo "selected"; } ?> value="2 años">2 años</option>
<option <?php if($perfil['experiencia'] == "5 años"){ echo "selected"; } ?> value="5 años">3 años</option>
here is the solution I needed to validate the option the correct question was to search within an array if the word x existed value="presentable">presentable
You could use the function
explode
, i.e. split a string into multiple strings.Possible example:
Your second question, I'm not entirely clear what function you really want to create. Let's see if I can still guide you a little with him
foreach
.Add the attribute
selected
to youroption
in case if it exists in our array ($cadena
).Result:
DEMO