NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page [PHP] in_array for multidimensional arrays

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search
6 members in live chat ~  


Reply
 
LinkBack Thread Tools
Old 04-14-2011, 02:42 PM THREAD STARTER               #1 (permalink)
Tech Support
Join Date: Mar 2005
Posts: 4,944
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics

Smile [PHP] in_array for multidimensional arrays


Simple function to check if a value exists in a multidimensional array.

PHP Code:
function multi_in_array($value$array)
????: NamePros.com http://www.namepros.com/code/711084-php-in_array-for-multidimensional-arrays.html
{
    foreach (
$array AS $item)
    {
        if (!
is_array($item))
        {
            if (
$item == $value)
            {
                return 
true;
            }
            continue;
        }

        if (
in_array($value$item))
        {
            return 
true;
        }
        else if (
multi_in_array($value$item))
        {
            return 
true;
        }
    }
    return 
false;
}

// Example
$array = array(
    
'Test' => array('test1''test2''test3'),
    
'Hmm'  => array('hmm1''hmm2''hmm3')
????: NamePros.com http://www.namepros.com/showthread.php?t=711084
);

var_dump(multi_in_array('test2'$array));
var_dump(multi_in_array('hmm1'$array));
var_dump(multi_in_array('alsdkfj'$array));

// bool(true) bool(true) bool(false) 
Eric is offline   Reply With Quote
Old 04-14-2011, 08:03 PM   #2 (permalink)
 
BillyConnite's Avatar
Join Date: Jul 2005
Location: Coffs H, Australia
Posts: 3,456
BillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond repute
 


Wildlife Parkinson's Disease Parkinson's Disease
Thanks Eric

I'd leave rep for you, but i can't

Nothing but quality snippets from you
BillyConnite is offline   Reply With Quote
Old 04-15-2011, 09:50 PM   #3 (permalink)
NamePros Member
Join Date: Apr 2011
Posts: 26
saima.spider is an unknown quantity at this point
 



good function similar one avilable in php.net
saima.spider is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Arrays search help !! Plzzzz Junior Programming 4 04-27-2004 02:02 AM

 
All times are GMT -7. The time now is 07:40 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger