Find the exact word position in string

后端 未结 5 1238
一个人的身影
一个人的身影 2020-12-22 15:28

Let\'s say I have a string.

$string = red,green,blue,yellow,black;

Now I have a variable which is the position of the word I am searching f

5条回答
  •  佛祖请我去吃肉
    2020-12-22 16:16

    A better way to solve this, would be by converting the string into an array using explode().

    $string = ...;
    $string_arr = explode(",", $string);
    //Then to find the string in 2nd position
    
    echo $string_arr[1]; //This is given by n-1 when n is the position you want.
    

提交回复
热议问题