What is the different meaning of the if-statement ( if(condition -> condition) ) to the regular if-statement ( if(condition = condition)) ?
looking up for the meaning without success.
if ($erg->num_rows) {
echo "<p>Daten vorhanden: Anzahl ";
echo $erg->num_rows;
If you are familiar with OOP concepts in PHP, then you will be able to understand what is going on here, else I recommend you to firstly get your hands dirty with OOP in PHP
Here $erg->num_rows
is not a condition. ->
operator is used to access any attribute of the pointing class instance.
In simple words, this line:
if ($erg->num_rows)
checks if the number of rows is greater than zero (as suggested by the variable name), if yes then the following code will be executed.
Because 0
is false
and any other number is true
. That means if $erg->num_rows
returns 0
then condition will be evaluated to false
and if it returns value that is not 0
, then condition will be evaluated to true
.
->
operator has nothing to do with if
statements.
You need to read about Classes and Objects
Example:
<?php
class Erg {
public $num_rows; // class property
public function setNumRows( $val ) { // class function
$this->num_rows = $val;
}
}
// create object of class Erg
$erg = new Erg();
// set value of num_rows property to 0
$erg->setNumRows( 0 );
echo $erg->num_rows; // access num_rows property using '->'
// set value of num_rows property to 1
$erg->setNumRows( 1 );
echo $erg->num_rows; // access num_rows property using '->'
?>