PHP:根据其他字符串

时间:2017-06-05 06:14:21

标签: php string split delimiter explode

我想获得Split Parts的价值。

我的代码是:

<?php 
$password = "03,10,05,07,17,23";

$string = "::3:8:1::5::2:9::::6:::4::::::0:";

$string = explode(':', $string);

如何按$ password

的顺序打印$ string

$串[03],$串[10],$串[05],$串[07],$串[17],$串[23]

结果需要:391540

1 个答案:

答案 0 :(得分:1)

在这里你Live demo

$password = "03,10,05,07,17,23";

$string = "::3:8:1::5::2:9::::6:::4::::::0:";

$pass = explode(',', $password);
$code = explode(':', $string);

$result = '';
foreach ($pass as $pos) {
    $pos = ((int)$pos)-1;
    $result .= $code[$pos];
}

echo $result;