How can I split a delimited string into an array in PHP?

前端 未结 10 1684
失恋的感觉
失恋的感觉 2020-11-21 11:11

I need to split my string input into an array at the commas.

How can I go about accomplishing this?

Input:

9,admin@example.com,8
10条回答
  •  走了就别回头了
    2020-11-21 11:50

    Use explode() or preg_split() function to split the string in php with given delimiter

    // Use preg_split() function 
    $string = "123,456,78,000";  
    $str_arr = preg_split ("/\,/", $string);  
    print_r($str_arr); 
      
    // use of explode 
    $string = "123,46,78,000"; 
    $str_arr = explode (",", $string);  
    print_r($str_arr); 
    

提交回复
热议问题