## 连续两天加班了，想不出这个公式 数组变换，PHP语言描述

cups_book 发布于 2014/07/06 14:22

1

```\$arr1=\$arr2=array();
foreach(\$array_info as \$k=>\$v){
if(\$k%2==0){
\$arr1=array_merge(\$arr1,explode(',',\$v));
}else{
\$arr2=array_merge(\$arr2,explode(',',\$v));
}
}```

0

```<?php
\$array_info = array(
'1,2,3',
'4,5,6',
'7,8,9',
'A,B,C',
'D,E,F',
'G,H,I',
);
function format_array(\$array=array())
{
if(is_array(\$array))
{
foreach(\$array AS \$k => \$v)
{
\$result_num = \$k%2;
\$temp_array[\$result_num][] =  \$v;
}
}else{
return array();
}

foreach(\$temp_array AS \$key => \$value)
{
\$new_array[\$key] = implode(',', \$value);
}
return \$new_array;
}
print_r(format_array(\$array_info));
?>```

0
1,3,5行合并一行      2，4，6合并一行
0

0

0
```\$arrOrigin = array(
'123',
'456',
'789',
'ABC',
'DEF',
'GHI',
);

\$keyMap1 = range(0, count(\$arrOrigin) - 1, 2);
\$keyMap2 = range(1, count(\$arrOrigin) - 1, 2);

\$result1 = \$result2 = '';
foreach(\$keyMap1 as \$indexValue){
\$result1 .= \$arrOrigin[\$indexValue];
}

foreach(\$keyMap2 as \$indexValue){
\$result2 .= \$arrOrigin[\$indexValue];
}

echo ( \$result1 ).PHP_EOL;
echo ( \$result2 ).PHP_EOL;
/*
123789DEF
456ABCGHI
*/```
0

0

+12306
0

0