i have this code
$courses = array("name_lic", "name_mes", "name_dou");
How i can add to array if name_lic, name_mes, name_douc
are defined?
For example: name_lic
is defined then, is insert in array, name_mes
is not defined or is empty then is not inserted in the array and name_dou
also.
basically the array only can have strings that are defined
in my example should be:
$courses = array("name_lic");
I'm going to guess that "inserted by user" means a value present in $_POST
due to a form submission.
If so, then try something like this
$courses = array("name_lic", "name_mes", "name_dou");
// Note, changed your initial comma separated string to an actual array
$selectedCourses = array();
foreach ($courses as $course) {
if (!empty($_POST[$course])) {
$selectedCourses[] = $course;
}
}
Do you mean something like
if (isset($name_lic)) {
$courses[] = $name_lic;
}
... etc for name_mes, name_dou
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With