Incorrectly root construction. Logically, it should look like this:
echo (что-то);
The brackets are optional, but it will be clearer for you. Now insert the ternary operator array_key_exists("test", $arr) ? 'ключ есть' : 'ключа нет' inside the parentheses array_key_exists("test", $arr) ? 'ключ есть' : 'ключа нет' array_key_exists("test", $arr) ? 'ключ есть' : 'ключа нет' which literally means true ? действие_для_true : действие_иначе; true ? действие_для_true : действие_иначе;
It turns out, we remove the brackets at the same time:
echo array_key_exists("test", $arr) ? 'ключ есть' : 'ключа нет';
Working Example: http://ideone.com/H68pwa
With the output of the key from the variable total:
$arr = array("test" => 1, "some" => 2); $key = 'test'; echo array_key_exists($key, $arr) ? "ключ $key есть" : 'ключа нет';
echo array_key_exists("test", $arr) ? 'ключ есть' : 'ключа нет';echo array_key_exists("test", $arr) ? 'ключ есть' : 'ключа нет';- Jean-Claude