Need to transform a string separated by commas into array

I have a string which is retrieved from a database that string is :

"2,2,2,2,2,2,2,2,2,2"

I want to convert it into an array so that I can perform an in_array function.

How can I do that ?

Answers


In PHP you can use the explode function (http://www.w3schools.com/php/func_string_explode.asp)

$str = "2,2,2,2,2,2,2,2,2,2";
print_r (explode(",",$str));

This will print print out as:

Array
(
[0] => 2
[1] => 2
[2] => 2
[3] => 2
[4] => 2
[5] => 2
[6] => 2
[7] => 2
[8] => 2
[9] => 2
)

Try explode

See http://www.php.net/explode for examples.


Need Your Help

Force push a floated <div> below another floated <div>

css html5 css3 html

Visit for my sample: http://codepen.io/anon/pen/qKBfE

Windows symlinks

windows powershell symlink

I am trying to create a symbolic link between a "reports" folder sitting inside each users home directory to the "reports" folder in the master.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.