Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.