Passing comma delimited string into array()

Posted on 2006-03-31
Medium Priority
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

Roonaan earned 500 total points
ID: 16344265
You can use:

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

LVL 15

Expert Comment

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

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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

840 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