<?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>NeatCN(NeatStudio工作室) &#187; array</title>
	<atom:link href="http://www.neatcn.com/tags/array/feed" rel="self" type="application/rss+xml" />
	<link>http://www.neatcn.com</link>
	<description>NeatStudio工作室</description>
	<lastBuildDate>Fri, 09 Dec 2011 13:07:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>array search</title>
		<link>http://www.neatcn.com/show-55-1.shtml</link>
		<comments>http://www.neatcn.com/show-55-1.shtml#comments</comments>
		<pubDate>Thu, 08 Apr 2010 04:09:31 +0000</pubDate>
		<dc:creator>膘叔</dc:creator>
				<category><![CDATA[PHP开发]]></category>
		<category><![CDATA[array]]></category>

		<guid isPermaLink="false">http://www.neatcn.com/?p=55</guid>
		<description><![CDATA[其实这是并不能算是一个search的方法，但我写这个方法是为了快速定位到数组里的key，以返回相应的值。 例如： $arr = array( 'a' => array( 'b' => array( 'c' => array( 'd' ) ) ), 'e' => array( 'f' => array( 'g' => array( 'h' ), 'i' => array( 'j' ) ) ) ); 象这样的数组，如果要取$arr['a']['b']['c']这样的值，写起来有点复杂，于是我这样写了一个函数 function search( &#8230; <a href="http://www.neatcn.com/show-55-1.shtml">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>其实这是并不能算是一个search的方法，但我写这个方法是为了快速定位到数组里的key，以返回相应的值。</p>
<p>例如：</p>
<pre class="brush:php">
$arr = array(
    'a' => array(
        'b' => array(
            'c' => array(
                'd'
            )
        )
    ),
    'e' => array(
        'f' => array(
            'g' => array(
                'h'
            ),
            'i' => array(
                'j'
            )
        )
    )
);
</pre>
<p>象这样的数组，如果要取$arr['a']['b']['c']这样的值，写起来有点复杂，于是我这样写了一个函数</p>
<pre class="brush:php">
function search( $keys , $arr ){
    if(!is_array($arr) &#038;&#038; !is_object($arr)){
        return ;
    }
    $keys = explode("." , $keys );
    $_err = false;
    foreach($keys as $key){
        if(isset($arr[$key])){
            $arr = $arr[$key];
        }else{
            $_err = true;
            break;
        }
    }
    if($_err == true)return ;
    return $arr;
}
</pre>
<p>这样就很好办了。。直接$e = search(&#8220;a.b.c&#8221; , $arr);<br />
就可以返回值了</p>
]]></content:encoded>
			<wfw:commentRss>http://www.neatcn.com/show-55-1.shtml/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

