如何在数组声明中实现循环
我有下面的数组 em_events(array(
) 并且需要插入下面的 foreach 来重复 $delete
链接。如何将 foreach 放入数组中?不知道如何最好描述一下这一点。
foreach ($EM_Events as $event) {
$delete = esc_url(add_query_arg(array('action'=>'event_delete', 'event_id' => $event->event_id, '_wpnonce'=> wp_create_nonce('event_delete_' . $event->event_id))));
}
em_events(array(
'owner'=>4,
'limit'=>10,
'scope'=>'all',
'format'=>'
<li class="even portfolio-entry">
<div class="entry-thumb standard">
<a class="thumblink" href="'.$delete.'"><span class="thumbnail">#_EVENTIMAGE{220,220}</span><span class="extra"><strong>Edit Event</strong></span></a>
</div>
<div class="entry-title">
<a href="#_EVENTURL" title="#_EVENTURL" rel="bookmark"><span style="color:#00b1d9;">PREVIEW EVENT POST</span><span>#F #j, #Y</span>#_NAME</a>
</div>
</li>
'
));
I have the below array em_events(array(
and need to insert the below foreach to repeat the $delete
link. How do in put a foreach into an array? Not sure how best to describe this.
foreach ($EM_Events as $event) {
$delete = esc_url(add_query_arg(array('action'=>'event_delete', 'event_id' => $event->event_id, '_wpnonce'=> wp_create_nonce('event_delete_' . $event->event_id))));
}
em_events(array(
'owner'=>4,
'limit'=>10,
'scope'=>'all',
'format'=>'
<li class="even portfolio-entry">
<div class="entry-thumb standard">
<a class="thumblink" href="'.$delete.'"><span class="thumbnail">#_EVENTIMAGE{220,220}</span><span class="extra"><strong>Edit Event</strong></span></a>
</div>
<div class="entry-title">
<a href="#_EVENTURL" title="#_EVENTURL" rel="bookmark"><span style="color:#00b1d9;">PREVIEW EVENT POST</span><span>#F #j, #Y</span>#_NAME</a>
</div>
</li>
'
));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想你想要的是这样的:
I think what you want is this:
使用
array_map()
在数组声明中构建 HTML 字符串。在array_map()
的回调中,使用sprintf()
建立一个占位符,以替换为您的 href 值生成器。Build your HTML string in the array declaration using
array_map()
. Inarray_map()
's callback, usesprintf()
to establish a placeholder to be replaced by your href value generator.这个怎么样:
What about this: