2 Replies - 334 Views - Last Post: 19 October 2009 - 09:27 PM Rate Topic: -----

#1 gtrizzle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-October 09

arrays

Post icon  Posted 19 October 2009 - 01:44 AM

<php
$producys=array("'soda','juice','alvaro',mineral water','water'")
for($x=0,$x<4,$x==)
{
echo$products($x)
echo"\n"
}
/*
echo$products[2]
echo$products[3]

/* this program has errors , i wonder if anyone could plaese help!
Is This A Good Question/Topic? 0
  • +

Replies To: arrays

#2 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: arrays

Posted 19 October 2009 - 01:59 AM

learn array from here Array
<?PHP
$products=array('soda','juice','alvaro','mineral','water','water');
for($x=0; $x<4; $x++)
{
echo $products[$x];
echo"\n";
}
echo $products[2];
echo $products[3];
?>


:)
Was This Post Helpful? 0
  • +
  • -

#3 Master Jake  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 16
  • View blog
  • Posts: 106
  • Joined: 27-February 09

Re: arrays

Posted 19 October 2009 - 09:27 PM

I'm sure noorahmad's information has already solved your problem, but I would like to give my 2 cents. This is basically explaining a bit about what each error was which occurred.

First Error:
$producys=array("'soda','juice','alvaro',mineral water','water'")



You do not need double quotes around the entire array itself, just around each individual item. Also, I recommend using the double quotes instead of the single quotes around items. Also, I think you spelled products wrong. Final mistake here is you missed the semi-colon at the end of the line (you did that for most of your lines actually).

Fixed:
$products  = array("soda", "juice", "alvaro", "mineral water", "water");



Second Error:
for($x=0,$x<4,$x==)



You mean $x++? :P

Fixed:
for($x=0,$x<4,$x++)



Third Error:
echo$products($x)
echo"\n"



Use some spaces, sheesh :blink: ;)
Semi-colon error as well. Also, you can combine multiple strings using the dot "." operator.

Fixed:
echo $products[$x] . "\n";



Final Error:
echo$products[2]
echo$products[3]



Semi-colons, and (again) space stuff.

Fixed:
echo $products[2] . $products[3];


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1