What does 'or' mean?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
detrox
Forum Newbie
Posts: 21
Joined: Wed Jun 04, 2003 1:27 am
Location: P.R.China

What does 'or' mean?

Post 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.
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post 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?
User avatar
detrox
Forum Newbie
Posts: 21
Joined: Wed Jun 04, 2003 1:27 am
Location: P.R.China

Post 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.
Post Reply