문제

When I check for a return value of a function I usually do this:

$my_value = get_field('some_field');
$my_value = $my_value ? $my_value : get_field('backup');

In Javascript I usually use or (||) to check a value and if not return an alternative i.e.

var my_value = get_field('some_field') || get_field('backup');

Is there something equivalent in php?

도움이 되었습니까?

해결책

Even faster:

$my_value = get_field('some_field') ?: get_field('backup');

Note that it tests if get_field('some_field') is true or false, and if true, return its value, else get_field('backup')...

다른 팁

well you have got it almost:

here is what helps you:

$my_value = isset($my_value) ? $my_value : get_field('backup');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top