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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:27:14+00:00 2026-05-26T00:27:14+00:00

im having a list of names james,steve,manson,charles in a array and im using the

  • 0

im having a list of names james,steve,manson,charles in a array and im using the explode function to separate them.

 $pieces = explode(",", $full);

foreach ($pieces as $p ){

    $piece[]=$p;
}

the problem that im having is that i can access the variables as

$piece[0];
$piece[1];

but the order differs time to time based on the input therefore i cant do a comparison. can someone suggest how to set the values so i can do the comparison as below

 if ($piece==='manson'){
//do something;
}else{
//do something
}

 if ($piece==='steve'){
//do something;
}else{
//do something
}
  • 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-26T00:27:15+00:00Added an answer on May 26, 2026 at 12:27 am
    $full = 'james,steve,manson,charles';
    $pieces = explode(",", $full);
    

    using a loop

    foreach($pieces as $p ) {
        // $p holds the name
        if($p==='manson') {
            //do something;
        } elseif($p==='steve') {
            //do something;
        } else {
            //do something
        }
    }
    

    also you could just check for the name in the array instead of looping

    if(in_array('steve',$pieces)) {
        echo 'We have Steve in the house';
    }
    

    or as Jon has suggested using a switch

    foreach($pieces as $p) {
        switch ($p) {
            case 'manson':
            case 'steve':
            case 2:
                echo "Fist pump for ".$p;
                break;
            default:
                echo "no fist in the air";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having a list of student names in a table , in the same
I am actually having a list of text boxes. I am using below code
Having a bit of trouble using the List.Find with a custom predicate i have
I've created a simple index using Zend_Search_Lucene for searching a list of company names,
There is a list of names and investment in two separate text fields, name
I have a List having country names in the list. And this list needs
Having: an entity Person which has a propriety Name a List<string> names loaded with
I'm currently having a really long list of university names that are not sorted
am using a listbox with multiple selection control. Now am having 200 names in
Here i am having a unordered list displaying two columns code and name .I

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.