Re: Re: tow dimenshional arrays

From: Date: Sun, 22 Feb 2004 01:23:38 +0000
Subject: Re: Re: tow dimenshional arrays
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-178464@lists.php.net to get a copy of this message
Namaste Adwinwijaya: I meant there's no PHP function neither to get a column nor to transpose the matrix. The first answer you gave us, retrieves the amount of items in the column, not the column itself as an array. And the second one, just prints the matrix, but does not transpose it. Joe-At: I suggest you to tell us your exact problem, maybe there's a way to solve it avoiding matrices, maybe there's a more suitable representation to the problem's parameters. Manu. PS: This function retrives the j column, assuming that the matrix has no non-numerical indeces: function getColumn($arr, $j) { if (isset($arr[$j]) && count($arr[$j])>0) { $result = array(); foreach($arr[$j] as $which) $result[] = $which; // You could make reference instead } } function getTranspose($arr) { if (count($arr)>0) { $result = array(); for($i=0; $i<count($arr); $i++) for($j=0; $j<count($arr[$i]); $j++) { if (!isset($result[$j])) $result[$j] = array(); $result[$j][$i] = $arr[$i][$j]; } } } Keep in mind this are inefficient functions. Manu. "Adwinwijaya" <adwinwijaya@yahoo.com.au> wrote in message news:91634614.20040222120737@yahoo.com.au... > Hello Manuel, > > Sunday, February 22, 2004, 5:47:02 AM, you wrote: > > MVA> As far as I know, there is no such a function. Maybe you should use a > MVA> different approach. > MVA> Manu. > > MVA> "Joe-At" <riej@yahoo.com> wrote in message > MVA> news:20040221145259.1539.qmail@pb1.pair.com... > >> Hallo, > >> 1) I want to work with the rows und columns of a tow dimensional > >> array[i][j]. With array[i] I get the i'th row. But how can I get the j'th > >> column? > >> 2) Is there any command to transpose a two dimensional array? > >> Thanks for help > > > 1. $array_j = $array[$i] ; > count($array_j) ; > > 2. > foreach($array as $sub_array){ > foreach($subarray as $key=>$value) > echo $key.'=='.$value ; > } > > > cmiiw > > -- > Best regards, > adwinwijaya > mailto:adwinwijaya@yahoo.com.au

« previous php.general (#178464) next »