Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,690 questions

55,449 answers

573 users

How to break a string into array of values in PHP

2 Answers

0 votes
$s = 'aaa, bbb, 231, ccc';
 
$arr = explode(',', $s);

print_r($arr);



/*
run:

Array
(
    [0] => aaa
    [1] =>  bbb
    [2] =>  231
    [3] =>  ccc
)

*/


answered May 25, 2014 by avibootz
edited Mar 3, 2025 by avibootz
0 votes
$s = 'aaa, bbb, 231, ccc, ddd';
 
$arr = explode(',', $s, 3); 

print_r($arr); 



/*
run:

Array
(
    [0] => aaa
    [1] =>  bbb
    [2] =>  231, ccc, ddd
)

*/

 



answered Mar 3, 2025 by avibootz

Related questions

2 answers 341 views
1 answer 150 views
150 views asked Apr 28, 2025 by avibootz
2 answers 235 views
1 answer 221 views
1 answer 266 views
...