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 Build a Basic PHP Website (2018) Listing and Sorting Inventory Items Displaying Categories

Not sure why I am getting this. Can anyone see something I can't?

Warning: strtolower() expects parameter 1 to be string, array given in /home/treehouse/workspace/Inc/functions.php on line 15

Here is line 15: if (strtolower($category) == strtolower($item["category"]))

4 Answers

Looks like you passing an array instead of string in strtolower function. Maybe you can share your full code for that file, so we can check it out for you.

Okay, Samuel. Here is the link to a snapshot of the code (Remember this is the path you're looking for: /Inc/functions.php on line 15).

https://w.trhou.se/dcg32apg4i

Extra Note: I am following this lesson (https://teamtreehouse.com/library/sorting-array-items) from Alena Holligan.

jamesjones21
jamesjones21
9,260 Points

Please do share the code, without code it would be hard to debug the error :)

Okay, Samuel. Here is the link to a snapshot of the code (Remember this is the path you're looking for: /Inc/functions.php on line 15).

https://w.trhou.se/dcg32apg4i

Extra Note: I am following this lesson (https://teamtreehouse.com/library/sorting-array-items) from Alena Holligan.

jamesjones21
jamesjones21
9,260 Points

give that a try to see if it works :)

  foreach ($catalog as $id => $item){
      if ($category == null OR strtolower($category) == strtolower($item["category"])){

If you look at line 10 in your catalog.php file, you assign an array to $section variable and you pass that variable to array_category function. In that function, $section variable is $category parameter at line 11 of function.php after that, you use strtolower on the $category which will produce an error because strtolower only accept string data types.

Looks like you don't update your catalog.php file from this video (https://teamtreehouse.com/library/displaying-categories). Alena has an if else block to set $section variable according to $_GET["cat"] value at line 8.

Hope it makes sense.

Okay, Samuel. I'll give it a go asap and get back to you on if it worked or not. Thanks for the help.

Edit: I have changed the catalog.php file and it works. Thanks for that. I didn't think at the time that it would cause this problem since it worked up until this point.