[英]Adding if statement in array item
I'm having trouble adding this我无法添加这个
<?php echo (set_value('first_name')) ? (set_value('first_name')) : ($row->first_name); ?>
to the value item in the following array到以下数组中的值项
$first_name = array(
'name' => 'first_name',
'id' => 'first_name',
'value' => ' ',
'maxlength' => '20',
'class' => 'text',
);
I tried using quotes and other methods but I get errors.我尝试使用引号和其他方法,但出现错误。 How should I format it for array?
我应该如何将其格式化为数组?
Do you mean like this?你的意思是这样吗?
$set_first_name = set_value('first_name');
$first_name = array(
'name' => $set_first_name ? $set_first_name : $row->first_name,
// etc
If using PHP 5.3, you can even shorten that to如果使用 PHP 5.3,您甚至可以将其缩短为
'name' => $set_first_name ?: $row->first_name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.