I'm attempting to create a fairly simple search function that queries the database for user profiles.
In order to do this, the function is going to take the string entered in the search bar and use the explode() function to seperate individual words into an array. These words are represented in the array $keywords as $keys.
I then iterate over the $keywords array, and for each $key I then iterate whether it matches any of the sql queries in the array $fields as $field. If it matches a field, then I want to get the index of the row and add it to an array $indexes.
I take the $indexes array and then find the row with the most matches. In other words, it will return the row which has matched the most via duplicate row indexes in the $indexes array. I then want to return this as my functions result.
Issue: I'm not sure how to retrieve the index of the current row being queried for keywords. This is probably a really simple fix, but I can't find a specific question that answers this.
Thanks.
The code I am mainly concerned is commented below.
foreach($keywords as $key){
foreach($fields as $field){
if($key = $field){
array_push($indexes, index($query->row())); /*add row at index to
$indexes array ??? */
}
}
}