PHP Array 简单操作小结

1. 创建Array: $arraySites = array();

2. addItem: $arraySites[$site->id] = $site;

3. 使用foreach遍历Array:

foreach ($arraySites as $site) { // 遍历每一个Site.
	// do something.
}

// Or:
foreach($array as $key=>$value)
{
echo "$key,$value ";
}

4. length: count($arraySite);

5.  打散/切割 Array : array_chunk($mails, $MAX_MAILS_PER_SMTP_SESSION, true);

该方法将会根据设定的大小对原数组进行切割, 生成多个小的数组(最后一个可能会少于单元大小), 第三个参数控制是否在打散后的数组内保留其原有key.

复制/移除 数组: http://liguoliang.com/2010/copy-and-remove-array-to-array-in-php/

This entry was posted in PHP and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>