嗨,我有一个这种格式的数组
<table>
<tr>
<td>array Name/index</td>
<td>d1</td>
<td>d2</td>
<td>d3</td>
</tr>
<tr>
<td>0</td>
<td>A</td>
<td>B</td>
<td>d</td>
</tr>
<tr>
<td>1</td>
<td>B</td>
<td>S</td>
<td></td>
</tr>
<tr>
<td>2</td>
<td>C</td>
<td></td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>A</td>
<td></td>
<td></td>
</tr>
</table>
现在我的任务是将其安排到一个数组
$ ARR =阵列(A,B,d,B,S,C,A); (以索引方式获取所有数组) 为此,我尝试了foreach,for循环,但我没有得到正确的结果
(请注意,表中的所有数组都是从查询中生成的)
答案 0 :(得分:0)
//input array
$array = array(
array('A','B','d'),
array('B','s'),
array('C'),
array('A')
);
$key_array = array();
foreach($array as $row) {
foreach($row as $key => $element) {
$key_array[$key][] = $element;
}
}
$result = array();
foreach($key_array as $row) {
foreach($row as $element) {
$result[] = $element;
}
}
print_r($result);
//result array
Array
(
[0] => A
[1] => B
[2] => C
[3] => A
[4] => B
[5] => s
[6] => d
)