vendredi 23 février 2018

PHP: Comparison not working when comparing strings

I have the following code:

<?php $decision_coding = $this->data['rowDetails']->decision_coding; ?>
[<?php echo $decision_coding. ' / ' . gettype($decision_coding);?>]
<select id="decision_coding" name="decision_coding" class="form-control">
    <option value="A" <?php echo ($decision_coding == 'A' ? 'selected' : '');?>>A</option>
    <option value="B" <?php echo ($decision_coding == 'B' ? 'selected' : '');?>>B</option>
    <option value="C" <?php echo ($decision_coding == 'C' ? 'selected' : '');?>>C</option>
    <option value="D" <?php echo ($decision_coding == 'D' ? 'selected' : '');?>>D</option>
    <option value="E" <?php echo ($decision_coding == 'E' ? 'selected' : '');?>>E</option>
    <option value="F" <?php echo ($decision_coding == 'F' ? 'selected' : '');?>>F</option>
</select>

This outputs [C / string] but the C option is not selected. Likewise, if it's any of the other characters, the relative option is not selected.

What's happening? Am I missing something obvious?

Aucun commentaire:

Enregistrer un commentaire