1

I'm trying to output a multidimensional array containing the results of a query using ElasticSearch into a Laravel Blade template. This seems like it should be so simple but I can't seem to avoid Getting an Undefined index: title error - don't understand as title is in the array?

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 ) ) ) ) ) )

I think the first few arrays are standard output from ElasticSearch relating to speed etc of search query. I need to output plugin title, description, author and tags. I have tried various foreach loops e.g:

foreach ($plugins as $plugin) {
    echo $plugin['title'];
    echo $plugin['description'];
    echo $plugin['author'];
    echo $plugin['tags'];
}

Where $plugins is the output of my query via the controller.

Any help much appreciated - this is normally so simple (note I gave up on blade specific syntax and have just tried php).

2
  • 1
    Don't you need to iterate on $plugins['hits']['hits'] and then echo $plugin['_source']['title'] ? Commented Jan 9, 2017 at 4:42
  • Great thanks val, this works. Only thing remaining is tags as in another array I believe. Commented Jan 31, 2017 at 11:31

1 Answer 1

0

Thanks Val, this works:

foreach ($plugins['hits']['hits'] as $plugin) {
            echo $plugin['_source']['title'];
            echo $plugin['_source']['description'];
            echo $plugin['_source']['author'];
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.