PHP:根据其他字符串从字符串中分解数据

PHP: Explode data from string based on other string

我正在尝试获取 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

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

需要结果:391540

给你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;