PHP 将二维数组转成1维数组 键名保持不变 并且去掉空元素

WBOY
Release: 2016-06-13 13:24:25
Original
1042 people have browsed it

PHP 将二维数组转成一维数组 键名保持不变 并且去掉空元素

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
array(
    0=>array(
        'zhangsan' => 'zhangsan (dae) abc'
    )

    1=>array(
        'lisi' => 'lisi (dae) abc'
    )
       
        2=>array()
)

转成
array(
    'zhangsan' => 'zhangsan (dae) abc',
    'lisi' => 'lisi (dae) abc',
)

Copy after login



谢谢了

------解决方案--------------------
PHP code
$a = array(
    0=>array(
        'zhangsan' => 'zhangsan (dae) abc'
    ),
    1=>array(
        'lisi' => 'lisi (dae) abc'
    ),
    2=>array()
);

$list = array();
foreach ($a as $v) {
    if (!$v) {
        continue;
    }
    $list[key($v)] = $v[key($v)];
} <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!