Page 1 of 1

array problem

Posted: Sat Feb 16, 2008 1:01 pm
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

Re: array problem

Posted: Sat Feb 16, 2008 1:24 pm
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 ),
)

Re: array problem

Posted: Sat Feb 16, 2008 2:37 pm
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.

Re: array problem

Posted: Sat Feb 16, 2008 4:47 pm
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];