Example #1
0
/**
 * Returns the first property of an object that is available.
 * 
 * See <ifnull> for a detailed description as this works the same way.
 * Difference is that this only checks against null but also if a value is set (weak comparison against false).
 * @return mixed The first set value or null of none found
 */
function ifavail()
{
    $args = func_get_args();
    $data = array_shift($args);
    if (count($args) == 0) {
        ScavixWDF\WdfException::Raise("ifavail needs at one argument");
    }
    if (is_array($data)) {
        $data = (object) $data;
    }
    if (!is_object($data)) {
        foreach (func_get_args() as $arg) {
            if ($arg) {
                return $arg;
            }
        }
        return null;
    }
    foreach ($args as $n) {
        if (avail($data, $n)) {
            return $data->{$n};
        }
    }
    return null;
}
Example #2
0
function forcedMove(&$numbers, &$backup, $type)
{
    foreach ($numbers as $pos => $item) {
        if (!is_array($item)) {
            continue;
        }
        $options = [avail($item)];
        $posList = $type($pos);
        foreach ($posList as $pos2) {
            if ($pos2 == $pos) {
                continue;
            }
            if (!is_array($numbers[$pos2])) {
                continue;
            }
            $options[] = avail($numbers[$pos2]);
        }
        if (count($options) < 2) {
            $numbers = $backup;
            $backup = null;
            return true;
        }
        $mustBeHere = call_user_func_array('array_diff', $options);
        if (count($mustBeHere) == 1) {
            fill($pos, reset($mustBeHere));
            return true;
        }
    }
    return false;
}