Current location: Hot Scripts Forums » Programming Languages » PHP » Search item in array


Search item in array

Reply
  #1 (permalink)  
Old 03-23-06, 04:43 AM
lcwei81 lcwei81 is offline
Newbie Coder
 
Join Date: Jun 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Search item in array

Hi all, I woul like to ask a question.
Array{
[0]=>Array{
['Child']=>"2",
['Parent']=>"6"
}
[1]=>Array{
['Child']=>"8",
['Parent']=>"7"
}
}
I would like to use in_array to check whether there is a number '7' in the ['Parent'] for all array. Or is anybody have better suggestion for me without travesal all the array to match the number i want.
Reply With Quote
  #2 (permalink)  
Old 03-23-06, 05:23 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
you will have to loop through all elements.. I don't see an efficiant use of in_array() here.
PHP Code:

for ($i 0$i count($array); $i++)

{
   if (
$array[$i]['Parent'] == 7)
   {
       
//Do whatever you want here
   
}

__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 03-23-06, 06:55 PM
lcwei81 lcwei81 is offline
Newbie Coder
 
Join Date: Jun 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Mnn... Thank you for you tips. But, I found it that I can use array_search to accomplish my task.
Reply With Quote
  #4 (permalink)  
Old 03-24-06, 05:24 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
no problem.
tho, array_search will return the "Child" element if it had the value 7 before any of the Parents.
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #5 (permalink)  
Old 03-24-06, 07:59 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
lol array_search rocks
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
Reply

Bookmarks


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SEO Expert Available nakulgoyal Job Offers & Assistance 2 08-14-04 12:38 PM
item search > item display eq1987 PHP 14 07-01-04 12:52 PM
linking to iframe not working :( j0d JavaScript 5 01-19-04 08:14 PM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 07:05 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.