Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
What does the -> operator do in PHP?
I was looking at an examples on using flashbuilder & mysql and i'm pretty new to php and found the following example, I was wondering what does -> do I haven't encountered it before i'm guessing it's some kind of assignment operator.
public function getAllEmployees($q) {
$sql = "SELECT * FROM $this->tablename WHERE first_name LIKE '%$q%' OR last_name LIKE '%$q%' OR email_address LIKE '%$q%'";
$stmt = mysqli_prepare($this->connection,$sql);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->emp_no, $row->birth_date, $row->first_name, $row->last_name, $row->gender, $row->hire_date, $row->phone_no, $row->email_address, $row->job_title);
while (mysqli_stmt_fetch($stmt)) {
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->emp_no, $row->birth_date, $row->first_name, $row->last_name, $row->gender, $row->hire_date, $row->phone_no, $row->email_address, $row->job_title);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
The example was from http://www.flashrealtime.com/flash-builder-4-and-p...
3 Answers
- just "JR"Lv 71 decade agoFavorite Answer
The -> is not an assignment operator, but an "index-of", used from a class.
Here:
$row = new stdClass(); // a totally useless "class" that defines the contents of a table or similar.
That "class", called "$row" is an array that contains "emp_no", "birth_date", "first_name" etc
mysqli_stmt_bind_result($stmt, $row->emp_no, $row->birth_date, $row->first_name, ...);
Why using a class when you don't need it?
$sql = "select * .... ";
$res = mysql_query($sql);
while ($row = mysql_fetch_array($res))
{
echo ($row['emp_no'] . ", " . $row['birth_date'] ... );
}
The difference? >5 times faster.
Not to confuse with the "=>" operator, as used to link "key" with "value":
foreach ($row as $key => $value) where $row is an associative array, such as:
[0] => "Mon"
[1] => "Tue"
[2] => "Wed".
- leonorLv 45 years ago
The "->" operator signifies a function within a class. In this case $doc is the class. Some where within the code there will probably be a line that looks similiar to this: $doc = new doc; That initiates the category and commits it to the variable $doc. When you wish to have to use any of the functions within the class doc, you could make the decision like this: $books = $doc->getElementsByTagName( "e-book" ); This tells the compiler that "getElementsByTagName" is a function with within the $doc class, and then appears to that category to execute the function. Eric