PHP Working with $_GET and $_POST in PHP $_GET and $_POST Using $_GET variables in a Function

Dublicate code

<?php
if (isset ($_GET['name'])) {
    $name = $_GET['name'];
}  
/* as the same if statement is within the function itself now
    the code snippet above is obsolete, isn' t it?
    If it is redundant, please update the code example so that others don' t get confused.
    Otherwise I appreciate any hint why the dublicate code is needed here.
   Thank you.
*/

function greeting() {
        if (isset ($_GET['name'])) {
            $name = $_GET['name'];
            echo "Hello, " . $name;
        }
}
greeting();
?>

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Staff

Hi there, devis ! I agree with you about the duplicate code. I'm not sure if it was included for emphasis, but I will bring it up with the education team. Thank you for bringing this to my attention! :smiley:

Hello Jennifer, thank you for the feedback :smiley: