Re: how to reverse a hudge multidimensional array?

From: Date: Thu, 31 Jan 2002 22:47:17 +0000
Subject: Re: how to reverse a hudge multidimensional array?
References: 1 2 3  Groups: php.db 
Request: Send a blank email to php-db+get-16333@lists.php.net to get a copy of this message
Bon soir Etienne, Like I say, "Inverting" an array is a chore, it's far easier to invert the pointers... but if you must do it:- For loop to control the first dimension using $i For loop to control the second dimension using $j $temp = $array[ $i ][ $j ]; $array[ $i ][ $j ] = $array[ $j ][ $i ]; $array[ $j ][ $i ] = $temp; Ok? =dn > thx a lot for your answer, > > in fact i only have to return one of the 15 datas, so it makes one column... > anyway, i already coded a solution with a while. My question was just to > know if it was possible to do it without repeating 1000000 times the same > processing. > > In fact i begin to believe that it is not possible to reverse the 2 > dimensions of an array... > > If you have a solution for me i m interested, even if it takes a lot of > processor ressources because i will have a dedicated server and there wont > be more than 30 users, not at the same time (that s for a stat intranet)... > just to correct my unprecision again, there will be 1M datas to process not > 15 because the array i ve to process is the result of my mysql query and > that this query will only return a single column of datas (count(*) ) > > Helllpppp :) > > Etienne > > > ----- Original Message ----- > From: "DL Neil" <PHPml@DandE.HomeChoice.co.uk> > To: "Etienne Durand" <magicfrog@wanadoo.fr> > Cc: <php-db@lists.php.net> > Sent: Thursday, January 31, 2002 10:44 AM > Subject: Re: [PHP-DB] how to reverse a hudge multidimensional array? > > > > Etienne, > > > > > Well i hope someone will be able to give me a solution... > > > Here s my problem: > > > I'm working with a hudge mysql table (about 15 columns and 1000000 > rows...) > > > > > > in fact i ve got to count the number of couples > > > ncompte/naffaire in > the > > > table and finaly calculate the number of couples that appear once, > twice.... > > > > > > here is the query i do: > > > $result = mysql_query("SELECT count(*) FROM datas GROUP BY > > > ncompte, > > > naffaire"); > > > > > > its result like something like this: > > > count(*) naffaire ncompte > > > 4 affaire1 compte1 > > > 4 affaire2 compte2 > > > 1 affaire3 compte3 > > > 2 affaire4 compte4 > > > 1 affaire5 compte5 > > > > > > (plus many more) > > > > > > > > > my final result should be: > > > $result[1] : 2 > > > $result[2] : 1 > > > $result[4] : 2 > > > > > > I manage to do this quite easily but i use a while instruction... > > > > > > while($row = mysql_fetch_array($result)) { > > > array_push($suite, $row["count(*)"]); > > > } > > > > > > As my table is very long the while takes a lot of time to complete... > > > So my question is : Is there a solution to return my array as follow : > > > > > > 1 2 3 1 4 7 > > > 4 5 6 ===>> 2 5 8 ??? > > > 7 8 9 3 6 9 > > > > > > It would allow me to not have to use this long long while.... > > > So if someone could telle me how to modify my query or what instructions > to > > > use to do that... > > > > > > =there are various functions in PHP to 'reverse' arrays, but I must > confess that I have never used them. > > Regardless, if there is one to suit your purpose, it will surely consume > CPU time to achieve the swap-over of > > 15M items. > > > > =your example "my final result should be:" talks of enumerated arrays, so > I shall assume this is the way you > > always use them. > > > > =you want to somehow achieve: > > array[1][1] = array [1][1]; > > array[1][2] = array [2][1]; > > array[1][3] = array [3][1]; > > etc > > (you know that you can't do the above, right!?) > > > > =thereafter the array would be processed by using a mechanism such as two > nested FOR loops to iterate through > > the row/column elements of the array, eg > > > > for ( i=1; i<15; i++ ); > > for ( j=1; j<1000000; j++ ); > > process( array[i][j] ); > > etc > > > > =can you leave the array where it is, and adjust the way the iterations > are managed? Instead of proceeding > > methodically by counting 'up', count 'down', eg > > > > for ( i=15; i>0; i-- ); > > for ( j=1000000; j>0; j-- ); > > process( array[i][j] ); > > etc > > > > =Regards, > > =dn > > > > > > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.db (#16333) next »