You are here: Re: search in an array of array « PHP Programming Language « IT news, forums, messages
Re: search in an array of array

Posted by Bob Bedford on 11/06/07 11:20

"Darko" <darko.maksimovic@gmail.com> a ιcrit dans le message de news:
1194279540.701715.22630@22g2000hsm.googlegroups.com...
> On Nov 5, 3:44 pm, "Bob Bedford" <b...@bedford.com> wrote:
>> Hello,
>>
>> I've an array of array(1,2,3,4). I'd like to retrieve the values in 3 and
>> 4
>> giving the values 1 and 2. How can I do that, how to search in an array
>> of
>> array ? in short, how to write the findvalue function ?
>>
>> $list = array();
>> array_push($list,array(1,1,'x','x');
>> array_push($list,array(1,2,'x','y');
>> array_push($list,array(2,1,'y','x');
>> array_push($list,array(2,2,'y','y');
>>
>> $result = array();
>> $result = findvalue(1,2); //should return 'x','y'
>>
>> function findvalue($a,$b){
>> //return the array of values...
>>
>> }
>>
>> Thanks for helping.
>>
>> Bob
>
> What have you tried already?
> We won't do your homeworks ;-)
>
>
I've a loop that goes trough all records of $list and check the values...not
sure is the best way to do so...my $list array contains about 1500 records
each is an array of 5 fields.

function findvalue($check1,$check2){
global $list

foreach ($list as $key => $value){
if(($value[0] = = $check1) and ($value[1] = = $check2)){
return array(strtoupper($value[3]),strtoupper($value[2]));
break;
}
}
}

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация