array problem

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

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

array problem

Post by itsmani1 »

I have following array

Code: Select all

Array
(
    [0] => 9.00 => 1
    [1] => 7.00 => 1
    [2] => 3.00 => 2
)
i used:

Code: Select all

foreach($shipsz as $key => $val)
{
    echo "$key = $val<BR/>";
}
 
and get following output:

Code: Select all

0 = 9.00 => 1
1 = 7.00 => 1
2 = 3.00 => 2
I want to now fetch
9 and 1
7 and 1
3 and 2

any solution
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: array problem

Post by Christopher »

This does not look like a valid PHP array. Is your array:

Code: Select all

array
(
    0 => array( 9.00 => 1 ),
    1 => array( 7.00 => 1 ),
    2 => array( 3.00 => 2 ),
)
(#10850)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: array problem

Post by Benjamin »

That's what I thought too, I think the array values actually are "9.00 => 1".

To answer the question though, you can use explode, trim and round to get the values.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: array problem

Post by s.dot »

array_keys() and array_values() may also be interesting ;)

Code: Select all

$keys = array_keys($array);
$values = array_values($array);
 
echo 'pair = ' . $keys[0] . ' -> ' . $values[0];
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply