PHP Build a Basic PHP Website (2018) Building a Media Library in PHP Working with _GET Variables

Amy Hsieh
Amy Hsieh
6,023 Points

I can't figure out what difference that isset[$_GET()] makes in that video.

if (isset($_GET["cat"])){
$section = "books";
} else if ($_GET["cat"]=="movies") {
$section = "movies";
} else if ($_GET["cat"]=="music") {
$section = "music";

Without the isset(), the code above makes sense to me. I don't know why we still need a isset () here. At the end of the video, Alina displayed what happened without isset(). Then I didn't get that part at all. Anyone could explain it for me?

1 Answer

Pascal Breitrück
Pascal Breitrück
Pro Student 3,204 Points

Hey, you check with the first line of code the the $_GET[‘cat’] and say hey 👋 is this set . If it’s set the code into the if block will executed. What will be the $pageTitle and $section if $_GET[‘cat’] is not set ????

You take isset() to safe your code. And if the $_GET[‘cat’] is not set PHP can ignore 9 lines of code .

I hope this is some food for thought.

Greets Pascal