Creating an index for searching in PHP

How can you only search for unique words with PHP so that I can learn the basics when doing a search?

I had several problems creating a multi-dimensional array for questions.

My first unsuccessful attempt is as follows.

# 1

$result = pg_query_params ( $dbconn, 
    "SELECT question_id, body
    FROM questions",
    array () 
);

while ( $row = pg_fetch_array ( $result ) ) {
    $question_body [ $row['question_id'] ] ['body'] = $row['body'];
    $question_index = explode ( " ", $question_body[ $row['question_id'] ] ['body'] ); 
    $question_index = array_unique ( $question_index ); 
}                                                                                                   
var_dump( $question_index ); 

The problem with this code is that it combines the words in each question. It seems that I cannot use explode, as it seems to make only a one-dimensional array.

I also run the following code trying to get question_id unsuccessfully .

# 2

while ( $row = pg_fetch_array ( $result ) ) {
    $question_body [ $row['question_id'] ] ['body'] = $row['body'];
    $question_index[ $row['question_id'] ] = explode ( " ", $question_body[ $row['question_id'] ] ['body'] );
    $question_index[ $row['question_id'] ]= array_unique ( $question_index );
}
var_dump( $question_index );
+3
source share
4

, str_replace . ,

$body = str_replace(array(',', '.'), '', $body);

.

, . , , , .

+2

( ) , DOM. :

PHP?

+2

, Postgres, LIKE . , PHP.

0

Source: https://habr.com/ru/post/1715756/