您的位置:首页 > 编程语言 > PHP开发

php如何增加一个元素到数组

2012-05-24 00:02 134 查看
Its better to not use array_push and just use what you suggested. The functions just add overhead.

//dont need to define the array, but in many cases its the best solution.
$cart = array();

//automatic new integer key higher then the highest existing integer
//key in the array, starts at 0
$cart[] = 13;
$cart[] = 'text';

//numeric key
$cart[4] = $object;

//text key (assoc)
$cart['key'] = 'test';
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐