Home  >  Article  >  Backend Development  >  把array分离两部分

把array分离两部分

WBOY
WBOYOriginal
2016-06-13 13:13:39887browse

把array分开两部分
把一个数组分开两部分,
一部分只取两条信息
另一部分除这两条信息外的所有信息
 比如 array(a=>1,b=>2,c=>3,d=>4 ,.....)
第一部分取到array(a=>1,b=>2);
第二部分取到array(c=>3,d=>4,......);


------解决方案--------------------

PHP code
$test=array('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5,'f'=>6);

$one=array_slice($test, 0,2);
$two=array_diff_key($test, $one);

var_dump($one,$two);
<br><font color="#e78608">------解决方案--------------------</font><br>
PHP code
$test = array('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5,'f'=>6);

$ar[] = array_slice($test, 0, 2);
$ar[] = array_slice($test, 2);

print_r($ar); <div class="clear">
                 
              
              
        
            </div>
Statement:
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
Previous article: 稿子统计字数 Next article: php怎么调用active控件