Split into two variables?

2019-01-27 12:38发布

Say I have the following: "44-xkIolspO"

I want to return 2 variables:

$one = "44";
$two = "xkIolspO";

What would be the best way to do this?

2条回答
混吃等死
2楼-- · 2019-01-27 13:22

Try this:

list($one, $two) = split("-", "44-xkIolspO", 2);

list($one, $two) = explode("-", "44-xkIolspO", 2);
查看更多
小情绪 Triste *
3楼-- · 2019-01-27 13:32

PHP has a function called preg_split() splits a string using a regular expression. This should do what you want.

Or explode() might be easier.

    $str = "44-xkIolspO";
    $parts = explode("-", $str);
    $one = $parts[0];
    $two = $parts[1];
查看更多
登录 后发表回答