Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Trees

Liquid Web Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Liquid Web Cloud VPS Hosting

8,759 questions

12,132 answers

573 users

How to reduce if else to a single return from function in PHP

1 Answer

0 votes
<?php

function is_empty1($username, $email) {
    if (!empty($username) && !empty($email)) {
        return TRUE;
    } else {
        return FALSE;
    }
}

function is_empty2($username, $email) {
    return (!empty($username) && !empty($email));
}

$user = "Amy";
$mail = "";

if (is_empty1($user, $mail)) {
    echo "not empty1";
} else {
    echo "empty1";
}

echo "<br/>";

if (is_empty2($user, $mail)) {
    echo "not empty2";
} else {
    echo "empty2";
}


     
/*
run:
 
empty1
empty2
 
*/


?>

 




answered Jul 8 by avibootz
...