Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9070269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:38:38+00:00 2026-06-16T17:38:38+00:00

i want to create a simple search function with an input field where the

  • 0

i want to create a simple search function with an input field where the user can search messages, stored in the database, by tags.

The problem is that the function returns ALL messages and not the one where the tags match.

Here is my try:

  public function getMatches($tagsGiven) {
  $mergedTagArray = array();
  $messageToTag = array();

  $messageRepo = $this->messageRepository->findAll(); // all messages from DB

  $messageTagsArray = explode(',', $tagsGiven); // tags given by the user

  foreach ($messageRepo as $oMessage) {
    $messageTag = $oMessage->getMessageTags(); // get tags from all messages   
    $storeTagsUnseri = unserialize($messageTag); // unserialize tags given by the user

    if (!in_array($messageTagsArray,$storeTagsUnseri)) {  //if tags from user matches tags from DB messages
      $messageToTag[] = $oMessage->getMessageText();     // get the message text from the DB message and store it in array
    }
  }
  return $messageToTag;     // return all message texts matching
}

}

Thank you very much!

Best regards

EDIT

if (array_intersect($messageTagsArray,$storeTagsUnseri)) {}

That did the trick.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:38:39+00:00Added an answer on June 16, 2026 at 5:38 pm

    Ok as I mantioned in my comment you are trying to see if object is not in array. You can’t do it like that, you have to convert your object to arrat first. So add this to your code if you dont expect multidimensional array:

     $storeTagsUnseri = unserialize($messageTag);
     $storeTagsUnseri = (array)($storeTagsUnseri);
    

    or just do:

     $json  = json_encode($storeTagsUnseri);
     $$storeTagsUnseriarray = json_decode($json, true);
    

    And than do array_intersect()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a simple app, where the user can take a photo.
JavaScript. I want to create simple script, that will be resize loaded image using
I want to create a simple app that shows me the city of the
I want to create a simple user registration form with First / Last name,
I have created a simple search field that will ajax in relevant search results
I want to create a very simple search partial. It has a text box,
i'm having a problem with this lisp function. I want to create a function
I want to create simple application that detects language(using Google API) of phrase and
I want to create simple app able to edit images. Main view of app
I want to create a simple Javascript program with a HTML interface. The program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.