Redux选项框架 - 幻灯片搜索
我当前使用slides“ field”使用redux插件将用于WordPress: https:/// docsv3.redux.io/core/fields/slides/index.html 。
问题是我有55个以上的幻灯片。
我可以以这种方式获得索引“ 0”的幻灯片:
if (isset($redux_demo['opt-slides']) && !empty($redux_demo['opt-slides'])) {
echo 'Slide 1 Title: ' . $redux_demo['opt-slides'][0]['title'];
echo 'Slide 1 URL: ' . $redux_demo['opt-slides'][0]['url'];
}
但是,我需要快速获得具有特定标题的幻灯片,例如“ homepage”,当前正在执行此操作的方式是使用php array_search(),然后浏览<<<< strong> $ redux_demo ['opt-slides'] 在找到具有给定名称的一个。
是否没有更优化的(性能明智)解决此问题的解决方案?
$redux_demo['opt-slides']["homepage"]['url']
Im currently using Redux plugin for WordPress with the slides "field": https://docsv3.redux.io/core/fields/slides/index.html .
The problem is i have 55+ slides.
I can get slide with index "0" this way:
if (isset($redux_demo['opt-slides']) && !empty($redux_demo['opt-slides'])) {
echo 'Slide 1 Title: ' . $redux_demo['opt-slides'][0]['title'];
echo 'Slide 1 URL: ' . $redux_demo['opt-slides'][0]['url'];
}
However i need to quickly get the slide with a specific title, like "homepage", the way im currently doing this is using PHP array_search() and go through every single slide in $redux_demo['opt-slides'] before it finds the one with the given name.
Isn't there a more optimized (performance wise) solution to this problem?, similar to:
$redux_demo['opt-slides']["homepage"]['url']
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试下一个代码,一个需要2个参数的小函数,您的幻灯片阵列搜索词标题中的搜索词(确切的标题,到目前为止,您可以用不那么天真的式表达式更改此行为。终于返回幻灯片的索引。
You could try the next code, a little function that needs 2 params your slides array The search term in Title (exact title, by now but you could change this behaviour with something not naive like a regex expression. Finally return the index of your slide.