Skip to main content
More affirmative answer (this is not a forum - see e.g. <http://meta.stackexchange.com/a/92115>. It is a think tank (see <http://meta.stackoverflow.com/a/325681>).
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

why not keepKeep things simple?:

<?php
    error_reporting(E_ALL); // makingMaking sure all notices are on

    function idxVal(&$var, $default = null) {
         return empty($var) ? $var = $default : $var;
    }

    echo idxVal($arr['test']);         // returnsReturns null without any notice
    echo idxVal($arr['hey ho'], 'yo'); // returnsReturns yo and assigns it to the array index,. nice
Nice
?>

why not keep things simple?

<?php
error_reporting(E_ALL); // making sure all notices are on

function idxVal(&$var, $default = null) {
         return empty($var) ? $var = $default : $var;
  }

echo idxVal($arr['test']);         // returns null without any notice
echo idxVal($arr['hey ho'], 'yo'); // returns yo and assigns it to array index, nice

?>

Keep things simple:

<?php
    error_reporting(E_ALL); // Making sure all notices are on

    function idxVal(&$var, $default = null) {
        return empty($var) ? $var = $default : $var;
    }

    echo idxVal($arr['test']);         // Returns null without any notice
    echo idxVal($arr['hey ho'], 'yo'); // Returns yo and assigns it to the array index. Nice
?>
Source Link
gts
  • 627
  • 5
  • 13

why not keep things simple?

<?php
error_reporting(E_ALL); // making sure all notices are on

function idxVal(&$var, $default = null) {
         return empty($var) ? $var = $default : $var;
  }

echo idxVal($arr['test']);         // returns null without any notice
echo idxVal($arr['hey ho'], 'yo'); // returns yo and assigns it to array index, nice

?>
Post Made Community Wiki by gts