Seriously, Google?

(Solved! It’s basically the means of getting a child property. For example, the C# equivalent of ($vector3->x) would be Vector3.x )

Okay, Google has majorly failed me. [:P] Apparently “->” is some kind of parameter, so it ignores it when I search the web for it. Se here’s my (very noobish) question: What on earth does “->” do? It’s obviously some kind of inheritor, but as google can’t help me on this one, I have no choice but to ask here.

for further context, this is the line of code I’m looking to clarify:

[php]while($i < 10)
{
$meta = $result->fetch_object();
echo “

” . $meta->company_name . “”;
$i += 1;
}[/php]

$result is the result (heh) of a connection query to the database, basically storing all the forms from it. The code loops through the first ten forms, printing them out fine. What I don’t understand is how it cycles through the forms: neither $meta nor $result has any relation to $i. I thought it was part of fetch_object(), but the docs don’t say anything about cycling through forms, so I’m trying to understand what “->” means.

Code, don’tcha just love it? [:P]

You could had simply just said it’s referencing a method or a property of an object. :wink: In this case it’s a method and a property.

P.S. The -> is an operator and if you would had google that you probably would had found your answer.

Looking at the code and I’m not totally sure, but a better way to write might be the following :

[php] while($meta = $result->fetch_object())
{
echo “

” . $meta->company_name . “”;
}[/php]

Though doing it the first way guarantees you 10 results. Though I personally like controlling that aspect (The number of results) with the query string in MySQL.
For example this is how I grab the top ten scores in a trivia game that I’m current developing ->
[php]$this->stmt = $pdo->query(“SELECT playername, highscore, play_date FROM highscores WHERE DATE(play_date) = CURDATE() ORDER BY highscore DESC LIMIT 10”);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service