470,596 Members | 1,146 Online

# search in an array of array

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
Nov 5 '07 #1
4 2633 \$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...
}
print_r(\$list);
not sure why you need a function here.
Nov 5 '07 #2
On Nov 5, 3:44 pm, "Bob Bedford" <b...@bedford.comwrote:
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
We won't do your homeworks ;-)

Nov 5 '07 #3
On Mon, 05 Nov 2007 17:14:20 +0100, Steve <no****@example.comwrote:
>\$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...
}

print_r(\$list);
Yet he wants to find the record in \$list.

OP: for a single search a foreach loop or customized array_filter come to
mind. If you have to search a lot of entries, you might want to build an
array of references, indezing the array. Be very, very sure you need it
--
Rik Wasmus
Nov 5 '07 #4

"Darko" <da**************@gmail.coma écrit dans le message de news:
On Nov 5, 3:44 pm, "Bob Bedford" <b...@bedford.comwrote:
>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

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 = = \$check1) and (\$value = = \$check2)){
return array(strtoupper(\$value),strtoupper(\$value));
break;
}
}
}
Nov 6 '07 #5

### This discussion thread is closed

Replies have been disabled for this discussion.

### Similar topics

 28 posts views Thread by joshc | last post: by 1 post views Thread by cyrvb | last post: by 10 posts views Thread by free2cric | last post: by 5 posts views Thread by Martien van Wanrooij | last post: by 36 posts views Thread by lovecreatesbeauty | last post: by 3 posts views Thread by mdh_2972 | last post: by 6 posts views Thread by flash | last post: by reply views Thread by Atos | last post: by reply views Thread by Debadatta Mishra | last post: by reply views Thread by Trystan | last post: by 2 posts views Thread by AlexandraMT | last post: by reply views Thread by ryjfgjl | last post: by reply views Thread by AlexandraMT | last post: by 3 posts views Thread by kjhyder | last post: by reply views Thread by drunkenHiker | last post: by 1 post views Thread by markleo | last post: by 1 post views Thread by EverettMiller | last post: by reply views Thread by DarlinRey | last post: by