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 870975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:34:02+00:00 2026-05-15T10:34:02+00:00

I am trying to create a script that checks if a certain value is

  • 0

I am trying to create a script that checks if a certain value is in a comma delimited string, and if the value is present, it should return true else it should return false.

Basically, I am trying to check if a user has voted for a specific person before, and if so, they cannot vote again, if they have not, vote and then add their uid to the database.

I am using explode to get all the values into an array, but I am unsure about the checking function, I have a few ideas but this is quite an important script so I wanted to see if there is a better way of going about it.

$test = "john,jack,tom";

$exploded = explode(",",$test);

$hostID = "john";

foreach($exploded as $one){
    if($one == $hostID){
        $return = TRUE;
    }else{
        $return = FALSE;
    };
};

Thanx in advance!

  • 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-05-15T10:34:03+00:00Added an answer on May 15, 2026 at 10:34 am
    • You could use in_array.
    • Some people prefer to use lowercase true and false.
    • The semicolon after } is not needed
    • $return = TRUE does not actually stop the function. Maybe you do return $return.
    • Some people like to put spaces after comma’s and keywords (e.g. foreach, if, else)
    • Some people prefer single quotes over double quotes

    Code:

    function find_name($name, $list)
    {
        $exploded = explode(',', $list);
        return in_array($name, $exploded);
    }
    
    var_dump(find_name('john', 'john,jack,tom'));
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 492k
  • Answers 492k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer When you decide security you usually deals with following terms:… May 16, 2026 at 10:21 am
  • Editorial Team
    Editorial Team added an answer The problem is that $start day is bigger than end… May 16, 2026 at 10:21 am
  • Editorial Team
    Editorial Team added an answer I am not a facebook expert, but I hit the… May 16, 2026 at 10:21 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Greetings. I am trying to create an autoconf configure script that automatically checks for
I'm trying to automate the build process for engineering group. As part of that
I'm trying to do a bit of fancy/experimental php so that you can include
I'm working on a script in R that processes some data and writes an
I'm tring to create an SSIS package to import some dataset files, however given
I was wrestling with mysql administrator trying to change the primary key on a
I'm trying to 'AJAX-ify' my site in order to improve the UI experience. In
1- Let's say my computer ip address is 111.11.111.11, and the server that my
I have a Drupal view which should output a video player using flash. I
i have a dynamic table that creates a div (new panel) for every TD

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.