在 array-php 中使用 if else
作为 php 新手,我无法弄清楚如何在 php 数组中使用 if else
。我尝试做这样的事情
function column_title($item){
$status=false;
if($item->uTestimonials_approval =='0')
$status=false;
else
$status=true;
//Build row actions
$actions = array(
$status ? 'unapprove' => sprintf('<a href="?page=%s&action=%s&id=%s">Unapprove</a>',$_REQUEST['page'],'unapprove',$item-> uTestimonials_id),:
'approve1' => sprintf('<a href="?page=%s&action=%s&id=%s">Approve</a>',$_REQUEST['page'],'approve',$item-> uTestimonials_id),
'delete' => sprintf('<a href="?page=%s&action=%s&id=%s">Delete</a>',$_REQUEST['page'],'delete',$item-> uTestimonials_id),
);
//Return the title contents
return sprintf('%1$s <span style="color:silver">(id:%2$s)</span>%3$s',
/*$1%s*/ $item-> uTestimonials_message,
/*$2%s*/ $item-> uTestimonials_id,
/*$3%s*/ $this->row_actions($actions)
);
}
,但我遇到了解析异常
Parse error: syntax error, unexpected T_DOUBLE_ARROW
,任何人都可以帮助我找出我到底做错了什么,提前谢谢
我完全同意反对票,但最好指定为什么有人这样做这样这个人就可以提高自己
being new to php i am not ble to figure out how to use if else
inside php array. i tried to do something like this
function column_title($item){
$status=false;
if($item->uTestimonials_approval =='0')
$status=false;
else
$status=true;
//Build row actions
$actions = array(
$status ? 'unapprove' => sprintf('<a href="?page=%s&action=%s&id=%s">Unapprove</a>',$_REQUEST['page'],'unapprove',$item-> uTestimonials_id),:
'approve1' => sprintf('<a href="?page=%s&action=%s&id=%s">Approve</a>',$_REQUEST['page'],'approve',$item-> uTestimonials_id),
'delete' => sprintf('<a href="?page=%s&action=%s&id=%s">Delete</a>',$_REQUEST['page'],'delete',$item-> uTestimonials_id),
);
//Return the title contents
return sprintf('%1$s <span style="color:silver">(id:%2$s)</span>%3$s',
/*$1%s*/ $item-> uTestimonials_message,
/*$2%s*/ $item-> uTestimonials_id,
/*$3%s*/ $this->row_actions($actions)
);
}
but i am getting following parsing exception
Parse error: syntax error, unexpected T_DOUBLE_ARROW
can any one help me to find what exactly i am doing wrong thanks in advance
I am perfectly fine for negative voting but its always better to specify why some one did that so that person can improve him/herself
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能对键值执行此操作:
请尝试如下操作:
You cannot do this for a key value:
Try something like this instead:
您不能在数组定义内执行此操作。
相反,您可以将它们添加到定义之后的数组中,如下所示:
You cannot do that inside the array definition.
Instead, you could add these to the array after the definition like this: