Page 1 of 1

What does 'or' mean?

Posted: Thu Jun 05, 2003 8:01 am
by detrox
In the code

Code: Select all

<?php
mysql_query("select * from sth") or die("error");
?>
What does the 'or' mean ?

and sometimes i can find 'as' like

Code: Select all

<?php
foreach ($lines as $line_num => $line) {
    echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
}
?>
what does this mean?I search in the manual but can not find it.Where can I find the usage of these ones.

Posted: Thu Jun 05, 2003 8:09 am
by []InTeR[]
If the mysql_query returns FALSE then the statement after the or is executed.

The foreach($array as $key=>$value) is some complicated....

Example:

Code: Select all

$array["key1"] = "value1";
$array["key2"] = "maybe value 2";
$array["key3"] = "yes, value 3";

// now the foreach as....
foreach($array as $key=>$value){
  echo "array ".$key." has as value: ".$value." <BR>\n"; 
}
/*
  This wil output
array key1 has as value: value1 <BR>
array key2 has as value: maybe value 2 <BR>
array key3 has as value: yes, value3 <BR>

*/
Understand?

Posted: Thu Jun 05, 2003 9:37 am
by detrox
So the 'or' here is no more than 'if (sth1 or sth2)'. Just because only when the first condition is false the second condition will be executed.That using process order of 'or'.

And 'as' is a kind of assignment operator who assign both the key and value of a array to two variables.