我试图将包含使用ElasticSearch的查询结果的多维数组输出到Laravel Blade模板中。这似乎应该是这么简单,但我似乎无法避免获取未定义的索引:标题错误 - 不理解标题是否在数组中?
Array ( [took] => 4 [timed_out] => [_shards] => Array ( [total] => 5 [successful] => 5 [failed] => 0 ) [hits] => Array ( [total] => 1 [max_score] => 4.7465386 [hits] => Array ( [0] => Array ( [_index] => partnerpages [_type] => plugins [_id] => 1 [_score] => 4.7465386 [_source] => Array ( [title] => PPRSS RSS news feed plugin [description] => PPRSS plugin allows you to share your latest news [author] => Louise Johnson [tags] => Array ( [0] => RSS [1] => syndication [2] => content [3] => news [4] => feeds ) ) ) ) ) )
我认为前几个数组是ElasticSearch的标准输出,与搜索查询的速度等有关。我需要输出插件标题,描述,作者和标签。我尝试了各种foreach循环,例如:
foreach ($plugins as $plugin) {
echo $plugin['title'];
echo $plugin['description'];
echo $plugin['author'];
echo $plugin['tags'];
}
其中$ plugins是我通过控制器查询的输出。
任何帮助非常感谢 - 这通常是如此简单(注意我放弃了刀片特定的语法,并且刚刚尝试过php)。
答案 0 :(得分:0)
感谢Val,这有效:
foreach ($plugins['hits']['hits'] as $plugin) {
echo $plugin['_source']['title'];
echo $plugin['_source']['description'];
echo $plugin['_source']['author'];
}