473,498 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2870
$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[1][2]);
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
What have you tried already?
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[1][2]);
Yet he wants to find the record in $list[1].

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
though, your code becomes somewhat unreadable by another coder.
--
Rik Wasmus
Nov 5 '07 #4

"Darko" <da**************@gmail.coma écrit dans le message de news:
11*********************@22g2000hsm.googlegroups.co m...
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

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;
}
}
}
Nov 6 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
3124
by: joshc | last post by:
If I have an array of data that I know to be sorted in increasing order, and the array is less than 50 elements, and I want to find the first element greater than a certain value, is a simple...
1
7095
by: cyrvb | last post by:
Hello, I'm a very very newbie in C# I did start 2 days ago, I get Visual Stuido 2005 C# I try to understand how to manage the arrays I did write this
10
9749
by: free2cric | last post by:
Hi, I have a single link list which is sorted. structure of which is like typedef struct mylist { int num; struct mylist *next;
5
2484
by: Martien van Wanrooij | last post by:
I have been using phpdig in some websites but now I stored a lot of larger texts into a mysql database. In the phpdig search engine, when you entered a search word, the page where the search word...
36
532
by: lovecreatesbeauty | last post by:
Any comments are welcome for following the two sequential search C functions of both integer and string versions. Though they are simple, please do not laugh at it :) Could you give your great...
3
1478
by: mdh_2972 | last post by:
I have an array of over 1000 links in a .JS file. I do not want to put the whole thing on my page because it would take to long to render the page. So how can I randomly pick 1 element from the...
6
6402
by: flash | last post by:
write a program that manipulates arrays of integers. The main program should call three functions: Insert, Delete, and Search. The Insert function should call a function Sort that sorts the array. ...
0
6957
by: Atos | last post by:
Binary search is used to locate a value in a sorted list of values. It selects the middle element in the array of sorted values, and compares it with the target value; that is the key we are...
0
10705
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7165
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7205
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4910
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4590
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.