Avatar

Search Phrase Drops to 3 Words When Clicking Second Page (Bugs)

by Auge ⌂, Thursday, September 12, 2019, 06:24 (1682 days ago) @ Micha

Hello

    // limit to X ($limit) words:
    $limit = 9; // Fictional variable with the new limit for the amount of words.
    if (count($search_array) > $limit) {
        foreach ($search_array as $search_item) {
            $stripped_search_array[] = $search_item;
        }
        $search_array = $stripped_search_array;
    }

What is your intention of the foreach-loop? The foreach-loop is a loop over all elements in then array. So, you first check the limit (e.g. 9 elements), and than you create a deep copy of the array containing all elements?!

Ahh, yes. It's only to muddle all the people.

Let's start again. If we cut every input to a length of X words (stored in $limit), we can simply use the function array_splice.

    // limit to X ($limit) words:
    $limit = 9; // Fictional variable with the new limit for the amount of words.
    array_splice($search_array, $limit);
    foreach ($search_array as $search_item) {
        $stripped_search_array[] = $search_item;
    }
    $search_array = $stripped_search_array;
 

Tschö, Auge

--
Trenne niemals Müll, denn er hat nur eine Silbe!


Complete thread:

 RSS Feed of thread