Part of the EllisLab Network
   
 
deep_in_array ()
Posted: 28 August 2006 04:13 PM   [ Ignore ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  7337
Joined  03-23-2006

I needed a quick function to search through a multi-dimensional array.  This might be a useful addition to the array helper.

/**
* Just a quick handy function to search down through multi-dimensional arrays
*/

function deep_in_array($value, $array) {
   
foreach($array as $item) {
       
if(!is_array($item)) {
           
if ($item == $value) return true;
           else continue;
       
}
      
       
if(in_array($value, $item)) return true;
       else if(
deep_in_array($value, $item)) return true;
   
}
   
return false;
}
 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
   
 
 
‹‹ JSON helper      Better Forms ››
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120473 Total Logged-in Users: 22
Total Topics: 126550 Total Anonymous Users: 2
Total Replies: 665395 Total Guests: 283
Total Posts: 791945    
Members ( View Memberlist )