Jump to content

Syntax Questions


Miichael

Recommended Posts

Hello

I am trying to learn improve my php skills and am having some problem with a couple of syntax issues.  I've tried researching but keep coming up with explainations that are vague at best.  If someone could point me to a good reference I would really really appreciate it.

What does "$stuff => something" or " 'stuff' => something" mean.  I've seen it used and I have a sense of it but I really don't understand it beyione the "if I pick up a rock I can crack open the nut" kind of thing.

What does "$stuff -> something" or "$stuff -> something(x) "mean?  This construct is really confusing me.

I would really appreciate some guidance and maybe an example that I can look at to help me understand.

Many thanks

Michael
Link to comment
https://forums.phpfreaks.com/topic/27971-syntax-questions/
Share on other sites

The $stuff->something or $stuff->something() are used when programming with classes.

[code]
<?php

class Stuff {

var $someVar;

function someFunction($someVar) {
  // Do something
    return $Modified_someVar;
}

function returnSomeVar() {
  // $this : current class/object
  return $this->someVar;
}
}

// create new class instance
$stuff = new Stuff();

// $stuff->someFunction(x) will call the function inside the class Stuff
$returnFromClass = $stuff->someFunction("blahblah");
echo $returnFromClass;

// ECHO: halbhalb

// $stuff->someVar will call the variable inside the class Stuff
$stuff->someVar = 'blihblih';
echo $stuff->returnSomeVar();
// ECHO: blihblih

?>
[/code]

The "=>" sign is only used while initializing arrays
[code]
<?php
// array(key => value)
$arrayOne = array(0 => 'Zero', 1 => 'One');
echo $array[0];
// ECHO: Zero

?>
[/code]

Hope this gives you an idee why these are used.
You better take a look at some tutorials about array's and tutorials about classes.
(If you're intrested take a look at some Object Oriënted tutorials as well)
If you google around you'll find a bunch of tut's about these subjects.
Link to comment
https://forums.phpfreaks.com/topic/27971-syntax-questions/#findComment-127952
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.