473,800 Members | 2,323 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($lis t,array(1,1,'x' ,'x');
array_push($lis t,array(1,2,'x' ,'y');
array_push($lis t,array(2,1,'y' ,'x');
array_push($lis t,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 2891
$list = array();
array_push($lis t,array(1,1,'x' ,'x');
array_push($lis t,array(1,2,'x' ,'y');
array_push($lis t,array(2,1,'y' ,'x');
array_push($lis t,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.c omwrote:
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($lis t,array(1,1,'x' ,'x');
array_push($lis t,array(1,2,'x' ,'y');
array_push($lis t,array(2,1,'y' ,'x');
array_push($lis t,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($li st,array(1,1,'x ','x');
array_push($li st,array(1,2,'x ','y');
array_push($li st,array(2,1,'y ','x');
array_push($li st,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************* ********@22g200 0h...legrou ps.com...
On Nov 5, 3:44 pm, "Bob Bedford" <b...@bedford.c omwrote:
>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($li st,array(1,1,'x ','x');
array_push($li st,array(1,2,'x ','y');
array_push($li st,array(2,1,'y ','x');
array_push($li st,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($chec k1,$check2){
global $list

foreach ($list as $key =$value){
if(($value[0] = = $check1) and ($value[1] = = $check2)){
return array(strtouppe r($value[3]),strtoupper($v alue[2]));
break;
}
}
}
Nov 6 '07 #5

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

Similar topics

28
3183
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 linear search the best here(for loop from beginning to end of array)? It seems like some other search algorithm like binary or whatever would be of no benefit on this data set.
1
7123
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
9784
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
2496
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 was found was displayed with about 2 lines before and 2 lines behind the search word itself. Let us say you look for "peanut butter" an the word is found in a larger text about sandwiches, even when it is on the 40th line of the text you would get...
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 suggestion to it? Thanks a lot. /*sequentially search a array of integers for a value. val: the integer is to be searched for in the array, array: array of integers, len: item count in the array. return the index of the value found in array, -1...
3
1503
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 array and then have the browser just place the 1 element only on my webpage. Also I also would like to know how to search for text in the array element and place it on my webpage. The first example is my main question.
6
6433
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. Here is a description of the three functions: Insert: Accepts as input the array and the element you want to insert into the array. The function should insert the element at the end of the array and should call the function Sort to sort the...
0
6982
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 searhing for in the array. If it islower than the target value then the search is made after that middle element and till the end of the array. If it is equal then the target value is found and the middle is returned. Otherwise, search is made from the...
0
10785
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 inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6813
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.