dimanche 27 septembre 2020

php in array function doesn't return true

I am a beginner in PHP, I am stuck with this problem. I am doing this for my checkbox.

I have a result from my database with the following data which is stored in this variable print_r($adoptive_parent->sector); with a type of string:

["Solo Parent","Indigenous Person","PWD"] 

now I tried using the explode function:

$checkbox_array = explode(",", $adoptive_parent->sector);

then i tried something like this:

if (in_array("Solo Parent", $checkbox_array)) {
     echo "true";
}else {
    echo "false";
}

why is this return false? can anyone help me? i want it to apply with my checkbox like this:

<label class="checkbox-inline"><input type="checkbox" name="sector[]" value="Solo Parent" <?php if(in_array("Solo Parent", $checkbox_array)){ echo " checked=\"checked\""; } ?> >Solo Parent</label>
<label class="checkbox-inline"><input type="checkbox" name="sector[]" value="Indigenous Person" <?php if(in_array("Indigenous Person", $checkbox_array)){ echo " checked=\"checked\""; } ?> >Indigenous Person</label>
<label class="checkbox-inline"><input type="checkbox" name="sector[]" value="PWD" <?php if(in_array("PWD", $checkbox_array)){ echo " checked=\"checked\""; } ?>>PWD</label>
      



Aucun commentaire:

Enregistrer un commentaire