Home >Backend Development >PHP Tutorial >PHP数组追加元素

PHP数组追加元素

WBOY
WBOYOriginal
2016-06-23 13:14:451600browse

<?php$a_1 = array("200kg","200cm");$a_2 = array("20kg","20cm","ok");$a_3 = array("2kg","2cm","ko");$a_4 = array("1kg","1cm","hello","world");$a[] = $a_1;$a[] = $a_2;array_push($a,$a_3,$a_4);//array_push() 函数等于多次调用 $array[] = $value。//如果用 array_push() 来给数组增加一个单元,还不如用 $array[] =,因为这样没有调用函数的额外负担。//如果第一个参数不是数组,array_push() 将发出一条警告。这和 $var[] 的行为不同,后者会新建一个数组。print_r($a);输出结果:Array(    [0] => Array        (            [0] => 200kg            [1] => 200cm        )    [1] => Array        (            [0] => 20kg            [1] => 20cm            [2] => ok        )    [2] => Array        (            [0] => 2kg            [1] => 2cm            [2] => ko        )    [3] => Array        (            [0] => 1kg            [1] => 1cm            [2] => hello            [3] => world        ))


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