$a = array(
'aa-15,10.24.0.15',
'bb-16,10.24.0.16',
'cc-17,10.24.0.17',
'dd-18,10.24.0.18',
'ee-19,10.24.0.19')
$b = array(
'10.24.0.18-10/1',
'10.24.0.18-10/10',
'10.24.0.19-5/10')
要如何變成下面的陣列
$c = array(
'dd,18,10/1',
'dd,18,10/10',
'ee,19,5/10')
這看起來像是 SQL join 耶?
樓主該不會是把資料從資料庫《select * from TABLE》之後,再用程式比對吧?
<pre class="c" name="code"><?php
$a = array(
'aa-15,10.24.0.15',
'bb-16,10.24.0.16',
'cc-17,10.24.0.17',
'dd-18,10.24.0.18',
'ee-19,10.24.0.19');
$b = array(
'10.24.0.18-10/1',
'10.24.0.18-10/10',
'10.24.0.19-5/10');
foreach($a as $aa)
{
list($x, $y) = explode(',', $aa, 2);
$as[$y] = $x;
}
foreach($b as $bb)
{
list($x, $y) = explode('-', $bb, 2);
$c[] = str_replace('-', ',', $as[$x]) . ','. $y;
}
var_dump($c);
?>