Find the exact word position in string

后端 未结 5 1237
一个人的身影
一个人的身影 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条回答
  •  旧时难觅i
    2020-12-22 16:22

    If you know that your words will be separated by commas you can do something like:

    $key = 2;
    $string = "red,green,blue,yellow,black";
    $arr = explode(",",$string);
    echo $arr[$key];
    

提交回复
热议问题