1
我需要使用一些數組並匹配它們,實際上我找到了一個解決方案,但這不是一個完美的解決方案,因爲我沒有3($ array)如何使用foreach打印另一個foreach? :d結合多個數組php
其實我用這個解決方案:
//options
$array = ["13", "14", "15"];
$tutti = [
"111" => "13",
"222" => "13",
"333" => "14",
"444" => "14",
"555" => "14",
"666" => "14",
"777" => "15",
"888" => "15"
];
$realarray = [];
$n_arrays = count($array); // 3 options
if ($n_arrays > 1) { // there is more of 1 option
foreach ($tutti as $key => $value) {
if ($value == $array[0]) {
foreach ($tutti as $key2 => $value2) {
if ($value2 != $array[0] && $value2 != $array[2]) {
foreach ($tutti as $key3 => $value3) {
if ($value3 != $array[0] && $value3 != $array[1]) {
echo "$key -> $key2 -> $key3<br>";
$realarray[] = "$key,$key2,$key3";
}
}
}
}
}
}
}
print_r($realarray);
你想完成什麼? – hellaminx
添加一些示例輸出 – nathanmac
是的,請提供預期的輸出。並澄清這一點:「因爲我沒有3($陣列)」你是什麼意思? – cyadvert