0

I wrote a program that reads data from a csv (saved as Unicode format in SQL Studio) and then does a few comparisons and prints out the results.

For some reason this simple if statement returns false eventhough when the data is printed it shows the correct results:

    foreach ($complete as $key => $val){    
    $INVOICE = 'INVOICE';
    $InvoiceType = $complete[$key][9];
    echo 'comparing' . $InvoiceType.'to'. $INVOICE;
         if ($InvoiceType == $INVOICE){
     echo 'I am inside a invoice';
     }
     else if ($InvoiceType == 'CREDIT'){
     $PayeeDocumentType = 'CM';echo 'I am inside a credit';
  }
  }

 ---------  Results  --------- 
comparingINVOICEtoINVOICEcomparingINVOICEtoINVOICE
7
  • 4
    that result doesn't look correct. How can it echo "comparingINVOICEtoINVOICE" twice? Commented May 4, 2011 at 19:02
  • 2
    Please paste the output of var_dump($InvoiceType); Commented May 4, 2011 at 19:02
  • can you var_dump $complete? Commented May 4, 2011 at 19:04
  • It is a part of a loop. Here are the results: comparingINVOICEtoINVOICEstring(13) "INVOICE" comparingINVOICEtoINVOICEstring(13) "INVOICE" Commented May 4, 2011 at 19:05
  • 1
    that's alarming... it should be string(7) "INVOICE" Commented May 4, 2011 at 19:08

2 Answers 2

1

My only guess is that $complete[$key][9] is an object and not a string.

What happens if you add print_r($complete[$key][9]) somewhere or modify the 2nd line of code to:

$InvoiceType = (string) $complete[$key][9];
Sign up to request clarification or add additional context in comments.

1 Comment

print_r($complete[$key][9]) prints "INVOICE". I also did gettype and it returned "string"
0

First guess try

$InvoiceType = trim($complete[$key][9]);

Also note the output of the var_dump in "view source" of the page. Basically see the raw output bring sent to the browser, maybe there are some invisible characters there.

Comments

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.