list($func, $field) = array_pad(explode('|', $value, 2), 2, null);
Two changes:
- It limits the size of the array returned by
explode()
to 2. It seems, that no more than this is wanted
- If there are fewer than two values returned, it appends
null
until the array contains 2 values. See Manual: array_pad() for further information
This means, if there is no |
in $value
, $field === null
. Of course you can use every value you like to define as default for $field
(instead of null
). Its also possible to swap the behavior of $func
and $field
list($func, $field) = array_pad(explode('|', $value, 2), -2, null);
Now $func
is null
, when there is no |
in $value
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…