<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dream☆Wing &#187; array</title>
	<atom:link href="http://www.dreamwing.org/tag/array/feed" rel="self" type="application/rss+xml" />
	<link>http://www.dreamwing.org</link>
	<description></description>
	<lastBuildDate>Sat, 05 Nov 2011 17:23:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>array_map()+create_function()</title>
		<link>http://www.dreamwing.org/php/array_map_plus_create_function.html</link>
		<comments>http://www.dreamwing.org/php/array_map_plus_create_function.html#comments</comments>
		<pubDate>Wed, 27 Aug 2008 18:10:55 +0000</pubDate>
		<dc:creator>Dream☆Wing</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>

		<guid isPermaLink="false">http://www.dreamwing.org/?p=119</guid>
		<description><![CDATA[在查询数据时习惯用SELECT *把所有数据都取出来扔到一个二维数组里
这样一来如果要取数据中具体某个值组成的数组的话一般是foreach出来扔到一个新数组里
例如数组$userarr = array(
array(&#8217;uid&#8217;=>1,&#8217;username&#8217;='dreamwing&#8217;),
array(&#8217;uid&#8217;=>2,&#8217;username&#8217;='cherry&#8217;)
);
要取得uid的集合的话，一般是foreach出来扔到一个新数组里。
写多了就回想有没其他方法来实现，数组的函数还是很多的
其中array_map()函数可以用回调函数处理数组的单元

这样
function return_uid($user)
{
return $user['uid'];
}
$uidarr = array_map(&#8217;return_uid&#8217;,$userarr);
即可
当然，与foreach相比，哪种写法效率高有时间再测试下
不过，如果可以像JQuery那样在第一个$param里定义函数多美&#8230;..
既然用都用了，那么多了解点array_map()这个函数吧
官网有几个例子：
1.同上
2.函数有N个参数，array_map()可以传N个数组.The number of parameters that the callback  function accepts should match the number of arrays passed to the array_map()
3.有点意思的使用方式，当回调函数$callback为null时，就回构造出一个数组的数组（传一个数组进去则返回相等的数组，传多个数组的话则返回1二维数组，以每个数组的同一键值组成的数组作为其的一个值）
4.如果传入的数组包含字符串键名时(associative)，当且仅当只传入一个数组时，返回的数组也会包含对应的字符串键名；如果传入多个数组的话，则永远是数字键名（XX数组？）
在官网有人举了个例子，用到了create_function()函数，借过来可以这样
$callback = create_function(&#8217;$uarr&#8217;,'return $uarr[\'uid\'];&#8217;);
$uidarr = array_map($callback,$userarr);
注：1.create_function()生成一匿名的函数(lambda?-style)，返回函数名或者FALSE
2.一般参数用单引号以达到不解析变量的目的
当然，用array_map()来处理一些问题还是很方便的，比如搜索结果关键词高亮等等，再适当配合下create_function()就更简洁了
]]></description>
		<wfw:commentRss>http://www.dreamwing.org/php/array_map_plus_create_function.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

