PHP iterating through a simple comma separated list

后端 未结 7 2085
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-01 03:06

I have a string which can be

$string = \"value.\";

OR

$string = \"value1, value2.\";

I want to iterate th

7条回答
  •  心在旅途
    2021-01-01 03:29

    When you explode, and there is no delimiter you have requested, the result at index 0 is the entire string.

     test
    //    [1] =>  test2.
    //    [2] =>  test3
    //    [3] =>  test4
    //)
    
    $string = "test test2. test3 test4";
    print_r( explode(',', $string) );
    //Array
    //(
    //    [0] => test test2. test3 test4
    //)
    

提交回复
热议问题