Home > Backend Development > PHP Tutorial > PHP 数组输出显示的问题

PHP 数组输出显示的问题

WBOY
Release: 2016-06-23 13:18:00
Original
988 people have browsed it

Array ( [0] => Array ( [0] => Array ( [ID] => 2IT14035A ) [1] => Array ( [ID] => 5IE14032S ) [2] => Array ( [ID] => 1IE15003B ) [3] => Array ( [ID] => 1IE15010C ) ) [1] => Array ( [0] => Array ( [ID] => 1IE14210D ) [1] => Array ( [ID] => 1IE15001A ) [2] => Array ( [ID] => 1IT15001G ) [3] => Array ( [ID] => 1IT14033S ) ) ) 
这是被分为两个组的数据,键值【0】和【1】里面分别又有3个数据
现在想分开显示
第一组:(键值为0的)2IT14035A, 5IE14032S,1IE15003B,1IE15010C
第二组:(键值为1的)1IE14210D,1IE15001A, 1IT15001G,1IT14033S
该怎么办呢 
谢谢大家


回复讨论(解决方案)

$a = array (  0 =>   array (    0 =>     array (      'ID' => '2IT14035A',    ),    1 =>     array (      'ID' => '5IE14032S',    ),    2 =>     array (      'ID' => '1IE15003B',    ),    3 =>     array (      'ID' => '1IE15010C',    ),  ),  1 =>   array (    0 =>     array (      'ID' => '1IE14210D',    ),    1 =>     array (      'ID' => '1IE15001A',    ),    2 =>     array (      'ID' => '1IT15001G',    ),    3 =>     array (      'ID' => '1IT14033S',    ),  ),);foreach($a as $k=>$v) $r[$k] = array_map('current', $v);print_r($r);
Copy after login
Array(    [0] => Array        (            [0] => 2IT14035A            [1] => 5IE14032S            [2] => 1IE15003B            [3] => 1IE15010C        )    [1] => Array        (            [0] => 1IE14210D            [1] => 1IE15001A            [2] => 1IT15001G            [3] => 1IT14033S        ))
Copy after login

还是要这样

$a = array (  0 =>   array (    0 =>     array (      'ID' => '2IT14035A',    ),    1 =>     array (      'ID' => '5IE14032S',    ),    2 =>     array (      'ID' => '1IE15003B',    ),    3 =>     array (      'ID' => '1IE15010C',    ),  ),  1 =>   array (    0 =>     array (      'ID' => '1IE14210D',    ),    1 =>     array (      'ID' => '1IE15001A',    ),    2 =>     array (      'ID' => '1IT15001G',    ),    3 =>     array (      'ID' => '1IT14033S',    ),  ),);foreach($a as $k=>$v) $r[$k] = join(',', array_map('current', $v));print_r($r);
Copy after login
Array(    [0] => 2IT14035A,5IE14032S,1IE15003B,1IE15010C    [1] => 1IE14210D,1IE15001A,1IT15001G,1IT14033S)
Copy after login

第二种。太感谢您了。
如果我想显示到网页上
第一组:2IT14035A,5IE14032S,1IE15003B,1IE15010C
第二组:1IE14210D,1IE15001A,1IT15001G,1IT14033S
直接print_r($r[0]) 对吗

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template