How can you search only unique words with PHP such that I can learn the basics in making the search?
I have had a few problems in making a multidimensional array for questions.
My first unsuccessful attempt is the following.
#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
, since it seems to make only a single 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 );