arjones85 wrote:All of the cases I had seen regarding while statements, when what appeared to be comparing, only used one = sign.
I was not aware that the statement when actually comparing used two = sign's, as I had yet to see a while statement that used two, so I thought it was a normal thing and was just curious as to why it was different than an if statement when comparing variables, which I now know it was not different.
My apologies, I thought I was being clear enough
A little clarification: when you do an "if(<condition>) {" or a "while(<condition>) {", the "<condition>" expression does not have to be a comparison. Whatever it is, it is evaluated and, if not already so, cast into a boolean true or false. Therefore, each of the following would all evaluate at true:
if(true) {
if(1) {
if(1 == 1) {
if($var = true) { // assignment here
if($var = 'non-emtpy string') { // another assignment
The following would all evaluate as false:
if(false) {
if(0) {
if(1 == 2) {
if($var = false) { // assignment here
if($var = '') { // another assignment