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

php子数组添加元素的问题

WBOY
WBOYOriginal
2016-06-06 20:34:08993browse

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>

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

建议看 php manual
zh
en

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