473,508 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Better multidimensional search

Hello all,
I'm pretty sure there's a better way to do this without having to explore
the whole array until a match is found, but the solution escapes me at the
moment:

foreach ($Array as $key)
if ($key[1]===$Whatever) {
$Found=$key[0];
break;
}

--
Guillaume Dargaud
http://www.gdargaud.net/
Jan 16 '08 #1
2 1307
On 16 Sty, 23:32, "Guillaume Dargaud" <USE_MY_WEB_F...@gdargaud.net>
wrote:
I'm pretty sure there's a better way to do this without having to explore
the whole array until a match is found, but the solution escapes me at the
moment:

foreach ($Array as $key)
if ($key[1]===$Whatever) {
$Found=$key[0];
break;
}
If you're looking for key instead of item you should write:

foreach( $array as $key =$item )...

looking for item? use array_search.
Jan 16 '08 #2
If you're looking for key instead of item you should write:
foreach( $array as $key =$item )...
Right, I should have written $item
looking for item? use array_search.
Hmmm... But I'm looking only in the 2nd 'column' of a 2D array. array_search
or in_array don't let me narrow down the search for a specific column. How
can I do that ?

--
Guillaume Dargaud
http://www.gdargaud.net/
Jan 17 '08 #3

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

Similar topics

2
1514
by: Ivan | last post by:
In my HTML forms (created by PHP) for attribute names I have been using multidimensional arrays as illustrated in the following: <table> <tr> <td> ID </td> <td> <input TYPE=hidden Name=frm_s...
2
1345
by: Henrik | last post by:
im reciving an error when i tries to read multidimensional XML data, into my system. I'm receving the same errors discriped at: http://support.microsoft.com/default.aspx?scid=kb;en-us;325695...
3
1859
by: matthewburton | last post by:
Hi everyone, I'm trying to write a program that will search a body of text and replace certain words (say, A, B, and C) with different words that I think are more appropriate (A1, B1 and C1). I...
3
1319
by: BobbyS | last post by:
I am trying to develop a multidimensional array for use of searching a very large database. I understand the concept of one and two dimensional arrays but this project would include up to 12 or 13...
1
1482
by: tarscher | last post by:
Hi all, 2 array questions; I have a multidimensional matrix. C1 C2 C3 C4 R1 R2 R3 R4 R5
2
3601
by: BB | last post by:
Hello, I have a HTML form containing multidimensional selects listing equipments and their quantitites. This allow the users to select the kind of equipment and quantitites they would like to...
5
2298
by: LittleCake | last post by:
Hi All, I have a multidimensional array where each sub-array contains just two entries, which indicates a relationship between those two entries. for example the first sub-array: =Array ( =30...
1
1429
by: kardon33 | last post by:
Good day all, First, I am rather new to C programming or at least don't use it enough to get used to it. My question, What part of my script needs to do is monitor a port and record the...
9
4473
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
0
7226
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,...
0
7125
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
7328
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
7499
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...
0
5631
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,...
1
5055
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
4709
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
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
422
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.