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

后端 未结 9 1419
清歌不尽
清歌不尽 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条回答
  •  青春惊慌失措
    2020-12-19 16:21

    I don't know of a way to do what you want, even though I've wanted to do the same thing many times before. For that specific case you could do

    $bar = substr($foo, 0, strpos($foo, " "));
    

    which stops there being one extra variable, but isn't exactly what you wanted.

提交回复
热议问题