473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to use max() for 2-dimensional array?

Hello,

I have an array which is being filled up from a SQL request. Now, I would like to know the max (and min) value of the first dimension.

How should I do that?

Thanks for any hints!

Stef
Nov 27 '07 #1
4 2677
Lumpy
69
Hello,

I have an array which is being filled up from a SQL request. Now, I would like to know the max (and min) value of the first dimension.

How should I do that?

Thanks for any hints!

Stef

I think you should be able to just use it telling it what dimension to look in. It's kind of hard for me to put this one in words, so let me just show you a quick example...
Expand|Select|Wrap|Line Numbers
  1. $test[0] = array(1,2,3,4,5);
  2. $test[1] = array(6,7,8,9,0);
  3. echo max($test[0]); ///would output a 5
  4. echo max($test[1]);///would output a 9
  5.  
You know what I am saying here? By telling it to look in dimension "0" or the first dimension it will only look through those values.

Hope this helps!
Nov 27 '07 #2
pbmods
5,821 Expert 4TB
Heya, Stef.

Probably the easiest way to do it would be to loop through the array and compare max() values:

Expand|Select|Wrap|Line Numbers
  1. $__max = 0;
  2.  
  3. foreach( $__array as $__vals )
  4. {
  5.     $__max = max( max($__vals), $__max);
  6. }
  7.  
This is a fairly CPU-intensive operation (esp. for large arrays). If you find that your script has to do this frequently, you might want to reconsider your process design.
Nov 27 '07 #3
Great. Second solution works perfectly. Merci!!
Nov 28 '07 #4
pbmods
5,821 Expert 4TB
Heya, Stef.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Nov 28 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Christian Hackl | last post by:
I honestly wasn't able to find an answer for this design question using Google and Google Groups, so I apologize if it is asked too frequently :) Anyway: Let's say I have a multidimensional array...
7
by: ffld | last post by:
Greetings all i am having a horrible time trying to pass a 2 dimensional array of doubles to a function... basically a watered down version of my code looks like: void t1(double a); int...
5
by: ritchie | last post by:
Hi, I am writing to ask if anyone can see why my array is not being sorted correctly? It's an array of 4 elements(ints 1,2,3,4) but after calling the selection sort it comes back sorted as...
5
by: sugaray | last post by:
Hi, my problem with calculating the size of an array is when I pass an array as a parameter to a function which perform the calculation, the result never comes right, like below: int...
3
by: inkexit | last post by:
I need help figuring out what is wrong with my code. I posted here a few weeks ago with some code about creating self similar melodies in music. The coding style I'm being taught is apparently a...
11
by: efialtis | last post by:
Hi to all, I am creating a program which plays a game. The game is played on a NxN square board. In every position of the board we may have a ball or not. Take for example the following 5x5...
3
by: j-in-uk | last post by:
Hi, I have a table with 2 columns and a one dimensional string array. I need to copy the string array to the table but I think I have to convert my string array to a 2dimensional array first with...
8
by: Relative0 | last post by:
I have a rather elusive problem and have spent some amount of time on it, I would very kindly appreciate it if anyone could give me insight on how to solve this problem. I tried to include what I...
15
by: DL | last post by:
say, we have the following: // declare an array myArray = ; // short hand? same as myArray = new Array ? // populate it myArray = 0; myArray = 0; myArray = 1; myArray = 0;
18
by: nk28 | last post by:
my question is that i have 512 mb ram .What is the max integer array size that i can declare in c. I recently experimented with different values and found that while i am able to create large values...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.