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
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Sat Feb 16, 2008 1:01 pm
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
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Sat Feb 16, 2008 1:24 pm
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)
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sat Feb 16, 2008 2:37 pm
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.
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Sat Feb 16, 2008 4:47 pm
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.