Passing comma delimited string into array()

Posted on 2006-03-31
Last Modified: 2008-01-09
Is this possible?
If :      $args = "item0,item1,item2";         // Argument String

And :      $args = array($args);            // Pass string into array

      $args[0] = "item0";
      $args[1] = "item1";
      $args[2] = "item2";

Do I have to use split(',',$args)

Also is this syntactically correct?
$args = (array)$args;

Question by:Schrodenger
    LVL 49

    Accepted Solution

    You can use:

    $args = explode(',', $string);

    LVL 15

    Expert Comment

    You can create an array with those three values using explode():

    $args_array = explode(",", $args);

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    The viewer will learn how to dynamically set the form action using jQuery.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now