Instead of calling the same function twice
<p>I'm first checking if a function returns a valid result, and then, if the result is valid, I need to use that in my script. But instead of checking once, and then coming back again to the function for its result, is there a way to do it all in one go? Here, <code>$strVal</code> is the variable I need to use in an querystring later.</p>

<pre><code>$conn = connect();

encrypt('HIs#$%.-','x');
decrypt('6507A27EB0521AFA0776F1A4F8033041','x');

//If the function returns a valid result, 
if (encrypt('Tom','x'))
{
 echo 'Success'.$strVal;//I'll use this in a querystring later.

}
else
{
 echo 'An error occurred';
}

//Encrypt string
function encrypt($strToEncrypt,$salt)
{
    global $conn;
    $elements = $conn-&gt;prepare("select hex(aes_encrypt(:what,:salt)) as encValue");
    $elements-&gt;bindParam(':what', $strToEncrypt);
    $elements-&gt;bindParam(':salt', $salt);
    $elements-&gt;execute();
    $row = $elements-&gt;fetch();
    $strVal = $row['encValue'];
    if(is_null($strVal)){return false;}else{return $strVal;}
}

//Decrypt string
function decrypt($strToDecrypt,$salt)
{
    global $conn;
    $elements = $conn-&gt;prepare("select aes_decrypt(unhex(:what),:salt) as decValue");
    $elements-&gt;bindParam(':what', $strToDecrypt);
    $elements-&gt;bindParam(':salt', $salt);
    $elements-&gt;execute();
    $row = $elements-&gt;fetch();

    if(is_null($row['decValue']))
    {echo "Null";}else{echo $row['decValue'];}
}
</code></pre>
