PHP の配列操作メソッドは、
1 次元配列
<br />array('0'=>'a',1=>'b',2=>'c',3=>'d',4=>'e',5=>'f');<br />
<br />array('a'=>'b','c'=>'d','e'=>'f');<br />-----解決策のアイデア---- -------------- ----
<br /><?php <br />$arr = array('0'=>'a',1=>'b',2=>'c',3=>'d',4=>'e',5=>'f','6'=>'g','7'=>'h');<br />$i = 0;<br />$len = count($arr);<br />$newArr = array();<br />while($i < $len){<br /> $newArr[$arr[$i]] = $arr[$i+1];<br /> $i += 2;<br />}<br />var_dump($newArr);<br />?> <br />
<br /><?php <br />$arr = array('0'=>'a',1=>'b',2=>'c',3=>'d',4=>'e',5=>'f','6'=>'g','7'=>'h','8'=>'i');<br />$i = 0;<br />$len = count($arr);<br />$newArr = array();<br />while($i < $len){<br /> $newArr[$arr[$i]] = array_key_exists($i+1,$arr)?$arr[$i+1]:null;<br /> $i += 2;<br />}<br />var_dump($newArr);<br />?> <br />
$a = array('0'=>'a',1=>'b',2=>'c',3=>'d',4=>'e',5=>'f', 'G');<br />foreach(array_chunk($a, 2) as $t) {<br /> $b[$t[0]] = @$t[1];<br />}<br />print_r($b);<br /><br />