Home > Backend Development > PHP Tutorial > php子数组添加元素的问题

php子数组添加元素的问题

WBOY
Release: 2016-06-06 20:34:08
Original
998 people have browsed it

array(1=>array()) 我想给1所对应的array中添加数据,php菜鸟求教。

回复内容:

array(1=>array()) 我想给1所对应的array中添加数据,php菜鸟求教。

<code>php</code><code>$arr = array(1=>array());
array_push($arr[1],'hello');//索引添加
...
$arr[1]['hello']=2;//关联添加
...
</code>
Copy after login

<code>php</code><code>$fruits = array(1=>array());
// 添加新元素
$fruits[1][] = 'Apple';
$fruits[1][] = 'Banana';
$fruits[1][] = 'Peach';
....
</code>
Copy after login

建议看 php manual
zh
en

Related labels:
php
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