-2

I am integrating an API and in some cases bonus field return value N/A and I want not to show N/A on the page.If the field has any text other than N/A then it shows the text.

I tried this:

    if(trim($value) != "N/A" && !is_null($value))
    {
        echo $value;
    }

But the above condition is not working.

Can anyone help me to make it working.

Thanks in advance.

B. Desai
  • 16,414
  • 5
  • 26
  • 47
dev tester
  • 327
  • 1
  • 10
  • 25
  • use OR (||) instead of AND && – Naresh Kumar Dec 15 '17 at 11:09
  • Not working for me – dev tester Dec 15 '17 at 11:36
  • will you show possible values for `$value`? – B. Desai Dec 15 '17 at 11:45
  • I used var_dumb() to check the type of data returned from the API, The type is string when it return N/A the var dump show string(20). 20 is the length of string but it should be 3. may be it includes white space. That's why i used trim. API will return numeric values and string values. Numeric values in case there is discount and string value to show message and N/A. – dev tester Dec 16 '17 at 03:35

1 Answers1

0

One answer from the oneliners club:

empty($value) or $value == 'N/A' or print($value);

"print" will only be reached if the $value is not set and is not "N/A"

Amarnasan
  • 14,939
  • 5
  • 33
  • 37