Home > Backend Development > PHP Tutorial > 把array分离两部分

把array分离两部分

WBOY
Release: 2016-06-13 13:13:39
Original
931 people have browsed it

把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>
Copy after login
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>
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