Shortcut for: $foo = explode(“ ”, “bla ble bli”); echo $foo[0]

后端 未结 9 1420
清歌不尽
清歌不尽 2020-12-19 15:48

is there a way to get the n-th element of a splitted string without using a variable?

My PHP code always looks like this:

$foo = explode(\" \", \"bla         


        
9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-19 16:14

    Not as far as I know although you could define a function and use that.

    function firstWord($string) {
      $foo = explode(" ", $string);
      return $string;
    }
    

提交回复
热议问题