Page 1 of 1

print array

Posted: Thu Sep 07, 2006 10:24 am
by Think Pink
Hello
I have the follwoing array

Code: Select all

Array ( [0] => X [1] => 3.5000 [2] => 3.5600 [3] => Y [4] => 2.7234 [5] => 2.7805 [6] => Z [7] => 5.1768 [8] => 5.2974 )
is there a way I could print it like
X 3.5000 3.5600
Y 2.7234 2.7805
Z 5.1768 2.2974

and another qusetion is: I have the follwing list...
x
3
4
Y
34
2
Z
1.125
3
... is there a way to create an array like this:

Code: Select all

$arr = array("X" => array([1] => 3, [2] => 4), 
        "Y" => array([1] => 34, [2] => 2), 
       "Z" => array([1] => 1.125, [2] => 3));
thankyou

hmmm

Posted: Thu Sep 07, 2006 10:42 am
by akimm
I'm not the best source but a possible suggestion for numerical comparison could be

Code: Select all

function compare($x, $y)
{
if ( $x[2] == $y[2] )
 return 0;
else if ( $x[2] < $y[2] )
 return -1;
else
 return 1;
}
and use this formula to compare each perhaps?


For your second problem I might suggest php.net explode function, also check split function.

if you're not familier, explode() takes strings and turns them into arrays.

I hope this helped

print array

Posted: Thu Sep 07, 2006 1:20 pm
by Think Pink
my mistake, I meant print not sort
So I wanted to to display teh results in the order I posted before, not to sort them.
I don't care if
results are
X | 5 | 4
Y | 3 | 78.4
....

the ideea was just to print them
Sorry

PS. Is there a way to change the subject?