DEV Community

Discussion on: Write good PHP - Lookup-arrays

Collapse
 
moopet profile image
Ben Sinclair

You've made the switch version look more verbose by changing return to echo, meaning it's no longer the same code as in the first example. If you were refactoring the first, you'd do:

$relative = $_GET['relative'];

switch ($relative) {
    case 'mother':
        return 'Harriet';
    case 'father':
        return 'Robert';
    case 'daughter':
        return 'Rachel';
    case 'grandmother':
        return 'Audrey';
}
Enter fullscreen mode Exit fullscreen mode

That could do with a default, of course, but you know what I mean :)

Collapse
 
joemoses33 profile image
Joe 🏴󠁧󠁢󠁷󠁬󠁳󠁿

You're totally right! I should update that! Thanks for mentioning it :)