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

Taylor O'Reilly
Taylor O'Reilly
2,636 Points

Is there a reason to repeat the setting of $section?

Instead of setting the $section variable in each 'if' statement, wouldn't this code be more appropriate for the "dry" methodology?

if(isset($_GET["cat"])){

if($_GET["cat"] == "books"){
  $pageTitle = "Books";
} else if ($_GET["cat"] == "movies"){
  $pageTitle = "Movies";
} else if ($_GET["cat"] == "music"){
  $pageTitle = "Music";
} else {
  $pageTitle = $pageTitle;
}
  $section = $pageTitle; // if there is a $pageTitle set this will set $section
} else {
  $section = null; // if $pageTitle is not set $section goes to null
}

are there any draw backs to doing it this way?

Sounds good, but hard to say for sure since we can't see what you are replacing. It always helps if you give a link to the video.