0

can't seem to start this working properly, any idea what could be the problem? The variable APP_NAME is equal to string 'test', if I do this if statement in a regular way it works as it should.

<?=form_radio('filter', 'y', $info['enable_categories'] == 'y' ? true : false, 'id="app" '.APP_NAME == "test" ? '' : 'disabled'.'')?>

The disabled parameter has to be put into the same last parameter as id.

But this way I get the false value even if APP_NAME equals 'test'.

The function form_radio has these parameters:

function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') so the extra parameter has to be ID and also the "disabled" string if the value is not equal to 'test'.

3
  • You pass this as parameter? Commented Sep 3, 2018 at 6:56
  • As constant, as I wrote it. Commented Sep 3, 2018 at 6:57
  • you pass this: $info['enable_categories'] == 'y' ? true : false, 'id="app" '.APP_NAME == "test" ? '' : 'disabled'.'' as parameters? Commented Sep 3, 2018 at 7:01

1 Answer 1

4

When you write

'id="app" '.APP_NAME == "test" ? '' : 'disabled'.''

the operator precedence makes this evaluate as

('id="app" '.APP_NAME) == "test" ? '' : 'disabled'.''

So you should use parentheses around the ternary clause:

'id="app" '.(APP_NAME == "test" ? '' : 'disabled'.'')

You can also get rid of the .''. Also the clause

$info['enable_categories'] == 'y' ? true : false

can be simplified to

$info['enable_categories'] == 'y'
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much for the explanation. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.