PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Think Pink
Forum Contributor
Posts: 106 Joined: Mon Aug 02, 2004 3:29 pm
Post
by Think Pink » Thu Sep 07, 2006 10:24 am
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
Last edited by
Think Pink on Thu Sep 07, 2006 1:22 pm, edited 1 time in total.
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Thu Sep 07, 2006 10:42 am
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
Think Pink
Forum Contributor
Posts: 106 Joined: Mon Aug 02, 2004 3:29 pm
Post
by Think Pink » Thu Sep 07, 2006 1:20 pm
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?