I have a list of <input>
elements and I am trying to simplify it so the code is tidier and cleaner. Here is what I have at the moment:
if($row['replies'] == '1') {
echo'<input type="submit" value="Locked">';
}else{
echo'<input type="submit" value="Lock">';
}
if($row['flagged'] == '1') {
echo'<input type="submit" value="Ignore">';
}
if($row['deleted'] == '1') {
echo'<input type="submit" value="Deleted">';
}else{
echo'<input type="submit" value="Delete">';
}
<input type="submit" value="Hello">
<input type="submit" value="Goodbye">
I am trying to simplify this using a multidimensional array, but I can't quite get my head around it. This is what I've tried so far:
$options = array("Lock"=>array("replies","Locked"),"Ignore"=>"flagged","Delete"=>array("deleted","Deleted"),"Hello","Goodbye");
foreach($options as $option) {
if(in_array($option[0], array('Lock','Deleted'), true) && $row[$option[1] == '1') {
echo'<input type="submit" value="'.$option[2].'">';
}else{
echo'<input type="submit" value="'.$option[0].'">';
}
}