<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Recursive (multidimensional) array search in PHP</title>
	<atom:link href="http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/</link>
	<description>by Justin D. Henry</description>
	<lastBuildDate>Fri, 16 Mar 2012 23:27:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: tuba</title>
		<link>http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/comment-page-1/#comment-2112</link>
		<dc:creator>tuba</dc:creator>
		<pubDate>Fri, 16 Mar 2012 23:27:04 +0000</pubDate>
		<guid isPermaLink="false">http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/#comment-2112</guid>
		<description>thank you very much!

saved enough time to search value in a multi dimentional array</description>
		<content:encoded><![CDATA[<p>thank you very much!</p>
<p>saved enough time to search value in a multi dimentional array</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sagan Internet Marke</title>
		<link>http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/comment-page-1/#comment-2107</link>
		<dc:creator>Sagan Internet Marke</dc:creator>
		<pubDate>Wed, 23 Nov 2011 12:19:30 +0000</pubDate>
		<guid isPermaLink="false">http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/#comment-2107</guid>
		<description>Works great! Make sure to replace &gt; with a greater than symbol and the $amp; with the Ampersand (6x). Thanks for providing this.</description>
		<content:encoded><![CDATA[<p>Works great! Make sure to replace &gt; with a greater than symbol and the $amp; with the Ampersand (6x). Thanks for providing this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ciprian Dimofte</title>
		<link>http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/comment-page-1/#comment-2099</link>
		<dc:creator>Ciprian Dimofte</dc:creator>
		<pubDate>Thu, 18 Aug 2011 23:23:21 +0000</pubDate>
		<guid isPermaLink="false">http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/#comment-2099</guid>
		<description>I&#039;m back with a solution.
Using these 2 functions will search multidimensional arrays and return ALL matching paths (items) NOT just a single item.

if(!function_exists(&#039;array_search_recursive&#039;)){
    function array_search_recursive($needle, $haystack, $key_lookin=&quot;&quot;){
       $path = NULL;
       if (!empty($key_lookin) &amp;&amp; array_key_exists($key_lookin, $haystack) &amp;&amp; $needle === $haystack[$key_lookin]) {
           $path[] = $key_lookin;
       } else {
           foreach($haystack as $key =&gt; $val) {
               if (is_scalar($val) &amp;&amp; $val === $needle &amp;&amp; empty($key_lookin)) {
                   $path[] = $key;
                   break;
               } elseif (is_array($val) &amp;&amp; $path = array_search_recursive($needle, $val, $key_lookin)) {
                   array_unshift($path, $key);
                   break;
               }
           }
       }
       return $path;
    }
}

// Recursive backtracking function for multidimensional array search
if(!function_exists(&#039;search_r&#039;)){  
    function search_r($value, $array){
        $results = array();
        
        if(is_array($array)){
            $path = array_search_recursive($value, $array);
            if (is_array($path) &amp;&amp; count($path) &gt; 0){
                $results[] = $path;
                unset($array[$path[0]]);
                $results = array_merge($results, search_r($value, $array));
            }else{
                
            }
        }
        
        return $results;
    }
}</description>
		<content:encoded><![CDATA[<p>I&#8217;m back with a solution.<br />
Using these 2 functions will search multidimensional arrays and return ALL matching paths (items) NOT just a single item.</p>
<p>if(!function_exists(&#8216;array_search_recursive&#8217;)){<br />
    function array_search_recursive($needle, $haystack, $key_lookin=&#8221;"){<br />
       $path = NULL;<br />
       if (!empty($key_lookin) &amp;&amp; array_key_exists($key_lookin, $haystack) &amp;&amp; $needle === $haystack[$key_lookin]) {<br />
           $path[] = $key_lookin;<br />
       } else {<br />
           foreach($haystack as $key =&gt; $val) {<br />
               if (is_scalar($val) &amp;&amp; $val === $needle &amp;&amp; empty($key_lookin)) {<br />
                   $path[] = $key;<br />
                   break;<br />
               } elseif (is_array($val) &amp;&amp; $path = array_search_recursive($needle, $val, $key_lookin)) {<br />
                   array_unshift($path, $key);<br />
                   break;<br />
               }<br />
           }<br />
       }<br />
       return $path;<br />
    }<br />
}</p>
<p>// Recursive backtracking function for multidimensional array search<br />
if(!function_exists(&#8216;search_r&#8217;)){<br />
    function search_r($value, $array){<br />
        $results = array();</p>
<p>        if(is_array($array)){<br />
            $path = array_search_recursive($value, $array);<br />
            if (is_array($path) &amp;&amp; count($path) &gt; 0){<br />
                $results[] = $path;<br />
                unset($array[$path[0]]);<br />
                $results = array_merge($results, search_r($value, $array));<br />
            }else{</p>
<p>            }<br />
        }</p>
<p>        return $results;<br />
    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sarita</title>
		<link>http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/comment-page-1/#comment-2098</link>
		<dc:creator>Sarita</dc:creator>
		<pubDate>Wed, 06 Jul 2011 12:23:33 +0000</pubDate>
		<guid isPermaLink="false">http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/#comment-2098</guid>
		<description>Great... exactly what i wanted... thanx..</description>
		<content:encoded><![CDATA[<p>Great&#8230; exactly what i wanted&#8230; thanx..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vinny</title>
		<link>http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/comment-page-1/#comment-2097</link>
		<dc:creator>Vinny</dc:creator>
		<pubDate>Fri, 27 May 2011 16:37:00 +0000</pubDate>
		<guid isPermaLink="false">http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/#comment-2097</guid>
		<description>How would I modify this to work with this array: http://i56.tinypic.com/345hdex.png</description>
		<content:encoded><![CDATA[<p>How would I modify this to work with this array: <a href="http://i56.tinypic.com/345hdex.png" rel="nofollow">http://i56.tinypic.com/345hdex.png</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: minh nhut</title>
		<link>http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/comment-page-1/#comment-2093</link>
		<dc:creator>minh nhut</dc:creator>
		<pubDate>Sun, 03 Apr 2011 13:19:45 +0000</pubDate>
		<guid isPermaLink="false">http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/#comment-2093</guid>
		<description>help me.if used recursion:
bool contains( char *haystack,  char *needle)</description>
		<content:encoded><![CDATA[<p>help me.if used recursion:<br />
bool contains( char *haystack,  char *needle)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vishal Porwal</title>
		<link>http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/comment-page-1/#comment-2092</link>
		<dc:creator>Vishal Porwal</dc:creator>
		<pubDate>Fri, 11 Feb 2011 05:20:47 +0000</pubDate>
		<guid isPermaLink="false">http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/#comment-2092</guid>
		<description>Be sure your multidimensional array contain boolean true false values. if it contains call the function with $strict=true,function is awesome and very helpful.</description>
		<content:encoded><![CDATA[<p>Be sure your multidimensional array contain boolean true false values. if it contains call the function with $strict=true,function is awesome and very helpful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/comment-page-1/#comment-2088</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Wed, 20 Oct 2010 09:03:36 +0000</pubDate>
		<guid isPermaLink="false">http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/#comment-2088</guid>
		<description>I get the following error:
Parse error: syntax error, unexpected &#039;=&#039;, expecting &#039;)&#039; in myphppage.php on line 132

Line 132 being :      foreach( $haystack as $key =&gt; $val ) {

Any ideas ?</description>
		<content:encoded><![CDATA[<p>I get the following error:<br />
Parse error: syntax error, unexpected &#8216;=&#8217;, expecting &#8216;)&#8217; in myphppage.php on line 132</p>
<p>Line 132 being :      foreach( $haystack as $key =&gt; $val ) {</p>
<p>Any ideas ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arun Sengupta</title>
		<link>http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/comment-page-1/#comment-2073</link>
		<dc:creator>Arun Sengupta</dc:creator>
		<pubDate>Wed, 12 May 2010 05:56:37 +0000</pubDate>
		<guid isPermaLink="false">http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/#comment-2073</guid>
		<description>well this is not what i was searching for , but it surely helped me think of the logic to make my own function for a certain process :) Thanks a lot .</description>
		<content:encoded><![CDATA[<p>well this is not what i was searching for , but it surely helped me think of the logic to make my own function for a certain process :) Thanks a lot .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sander</title>
		<link>http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/comment-page-1/#comment-2040</link>
		<dc:creator>Sander</dc:creator>
		<pubDate>Sat, 03 Oct 2009 21:44:55 +0000</pubDate>
		<guid isPermaLink="false">http://greengaloshes.cc/2007/04/recursive-multidimensional-array-search-in-php/#comment-2040</guid>
		<description>Thank you! I also couldn&#039;t get the examples on php.net to work in my script. This worked almost immediately!</description>
		<content:encoded><![CDATA[<p>Thank you! I also couldn&#8217;t get the examples on php.net to work in my script. This worked almost immediately!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

