Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Count Function: Help - Code Challenge

Create a new function in products.php called get_products_count. This should receive no arguments, and it should return the total number of products. This new function should call our existing get_products_all function and return the number of elements in the products array. Challenge LInk http://teamtreehouse.com/library/coding-the-getproductscount-function

What am I doing wrong?

function get_products_count() {
  $total = count(get_products_all);

  return $total;
};

I even tried

function get_products_count() {
  $products = (get_products_all);
  $total = count($products);

  return $total;
};

1 Answer

get_products_all is a function. Parentheses go after the function when you call it.

function get_products_count() {
  $products = get_products_all();
  $total = count($products);

  return $total;
};