View previous topic :: View next topic |
Author |
Message |
egoo -
Joined: 22 Jan 2008 Posts: 16
|
Posted: Wed Jun 11, 2008 7:33 pm Post subject: function list |
|
|
Please, correct the code in order to eliminate existing error, using list():
prices.php
<?php
$prices = array('Tires'=>100,'oil' => 10,'Spark plugs'=>4);
$products = array('Tires','oil','Spark plugs');
while($list($product,$price)= each($prices))//can't use the function return value in write context in prices.php
echo "$product - $price<br/>";
?>
Last edited by egoo on Thu Jun 12, 2008 9:02 am; edited 2 times in total |
|
Back to top |
|
|
abyssisthebest -
Joined: 30 Jun 2005 Posts: 319 Location: Boston, UK
|
Posted: Wed Jun 11, 2008 8:46 pm Post subject: |
|
|
Hi,
You could try the following code:
Code: | <?php
$data = array( 'Tires'=>'100', 'Oil' => '10', 'Spark Plugs' => '4');
foreach ($data as $product => $price){
echo "$product - $price <br />";
}
?>
|
Using the method above, also saves you from typing the product name twice. Hope that helps.
Craigy _________________ My online Portfolio |
|
Back to top |
|
|
DonQuichote -
Joined: 24 Dec 2006 Posts: 68 Location: The Netherlands
|
Posted: Wed Jun 11, 2008 11:46 pm Post subject: |
|
|
The error was that the function list was preceded by a $. |
|
Back to top |
|
|
|