Can you write the following in one line of code?
$foo = explode(":", $foo);
$foo = $foo[0];
Can you write the following in one line of code?
$foo = explode(":", $foo);
$foo = $foo[0];
As an alternative to list(), you may use array_shift()
$foo = array_shift(explode(':', $foo));
Yes, it's posible to do using list
:
list($foo) = explode(":", $foo);
Just completing @GSto answer, in case it helps:
I often have to deal with strings that can have 0 or more separators (colon in this example).
Here is a one-liner to handle such strings:
$first = stristr($foo,":") ? stristr($foo,":",true) : $foo;