How can PHP be used to automatically mark entries in a selection list based on values from multiple arrays?
To automatically mark entries in a selection list based on values from multiple arrays, you can iterate through the arrays and compare the values with the options in the selection list. If a match is found, you can add the 'selected' attribute to the option tag. This way, the option will be pre-selected when the selection list is displayed.
<?php
// Sample arrays with values to mark as selected
$array1 = ['value1', 'value2'];
$array2 = ['value3', 'value4'];
// Options for the selection list
$options = ['value1', 'value2', 'value3', 'value4'];
// Output the selection list with marked entries
echo '<select>';
foreach ($options as $option) {
$selected = (in_array($option, $array1) || in_array($option, $array2)) ? 'selected' : '';
echo "<option value='$option' $selected>$option</option>";
}
echo '</select>';
?>