Stuck at Exercise 6. Array Functions 1


#1

I have the following code:

<html>
    <p>
	<?php
	// Create an array and push 5 elements on to it, then 
    // print the number of elements in your array to the screen
    $foods = array();
    array_push($foods, "Banana");
    array_push($foods, "Apple");
    array_push($foods, "Noodles");
    array_push($foods, "Ramen");
    array_push($foods, "Burger");
    print count($foods);
	?>
	</p>
</html>

Is there something wrong with this code? If there ISN'T: Did anyone else get stuck on this exercise? Or is this just a bug?? Thanks for your help :slight_smile:


#2

hahahahaha... great.... In the descriptions I read "print" instead of "echo" several times now.
If I change the code to the following:

<?php
// Create an array and push 5 elements on to it, then 
// print the number of elements in your array to the screen
$foods = array();
array_push($foods, "Banana");
array_push($foods, "Apple");
array_push($foods, "Noodles");
array_push($foods, "Ramen");
array_push($foods, "Gratin");
echo(count($foods));

it asks me if I have used "array()"...

So I changed it even further to this:

<?php
// Create an array and push 5 elements on to it, then 
// print the number of elements in your array to the screen
$foods = array();
array_push($foods, "Banana");
array_push($foods, "Apple");
array_push($foods, "Noodles");
array_push($foods, "Ramen");
array_push($foods, "Gratin");
$nrObj = count($foods);
echo($nrObj);

and now it works..... @CodecademyModerators if it isn't too much work, I believe it would be better to change this... :slight_smile: