How would I check if the variable label_$value
exists?
E.g:
<?php foreach($status_values as $value => $label){ ?>
<input type="radio" name="status" value="<?php echo $value; ?>" <?php if($status == $value){ echo ' checked="checked"'; }?> />
<?php echo (isset("label_{$value}")) ? "label_{$value}" : $label; ?>
<?php } ?>
This gives error: Parse error: syntax error, unexpected '"' for the isset
But I dont get any syntax error when I have:
<?php echo ("label_{$value}") ? "label_{$value}" : $label; ?>
So I want to:
$label_foo
$label
you have to use variable variables. use
<?php
$label_test = "Hello";
$value = "test";
echo (isset(${"label_{$value}"})) ? "label_{$value}" : $label;
?>
That's not how you compile the variable name. Try isset(${"label_$value"});