function list

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
egoo
-


Joined: 22 Jan 2008
Posts: 16

PostPosted: Wed Jun 11, 2008 7:33 pm    Post subject: function list Reply with quote

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 View user's profile Send private message
abyssisthebest
-


Joined: 30 Jun 2005
Posts: 319
Location: Boston, UK

PostPosted: Wed Jun 11, 2008 8:46 pm    Post subject: Reply with quote

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 View user's profile Send private message Send e-mail MSN Messenger
DonQuichote
-


Joined: 24 Dec 2006
Posts: 68
Location: The Netherlands

PostPosted: Wed Jun 11, 2008 11:46 pm    Post subject: Reply with quote

The error was that the function list was preceded by a $.
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group