PHP string problem

Hi… I have started learning PHP only recently. But I stumbled upon a problem i can’t understand, and i guess, it’s one of the basics… Probably solution is very simple but still couldn’t figure it out…
I got this code:
FreePHPtest.com - Online PHP testing

for some reason, it only returns zeros, not the sentence… any help would be appreciated…

Try this:

<?php

//setup
$animals=array("fox","lion","bear");

//do someting
sort($animals);
print_r($animals);

//output
for ($x=0;$x<count($animals);$x++)
{
   echo "<br />" . $animals[$x] . " is a creature.";
}
?> 

2 problems:

  1. You need to print $animals[$x], not $animals[0], and
  2. you are using the addition (+) operator when you want to be using the string concatenation operator (.):
$animals=array("fox","lion","bear");

//do someting
sort($animals);
print_r($animals);

//output
for ($x=0;$x<3;$x++)
{
   echo "<br />".$animals[$x]." is a creature.";
}

yup, aamonkey is right, i’m programming delphi and java at most and forgot about + sign. Will edit my comment :slight_smile:

Thanks alot, guys :slight_smile: yes, dots are hard to get used to…

made changes and code runs fine…