Home > Backend Development > PHP Tutorial > PHP新手,求教大神!!

PHP新手,求教大神!!

WBOY
Release: 2016-06-23 14:38:54
Original
941 people have browsed it



下面是一段PHP的代码:

$a=array("name" => ($d = array("cat")) ,"Monday" =>( $c = array("dog") ));
array_push($d,"Horse","Bird");
print_r ($a);
?>


运行的结果是:


我想知道 我用了array_push 函数 可是为啥 “Horse” "Bird" 这两个值输出的时候没有吖?
应该怎么改一下才能有这两个追加的值呢??
谢谢!! 


回复讨论(解决方案)

你的$d、$c是什么?array_push()是将一个或多个单元压入数组的末尾(入栈) 。

你的用法有问题!

你那样只是把元素压进了$d的数组,而不是$a

你 print_r($d); 看看加到哪里去了

array_push($a['name'],"Horse","Bird");print_r ($a);
Copy after login
Array
(
    [name] => Array
        (
            [0] => cat
            [1] => Horse
            [2] => Bird
        )

    [Monday] => Array
        (
            [0] => dog
        )

)

谢谢两位大神的解答!!

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