Miichael Posted November 21, 2006 Share Posted November 21, 2006 HelloI 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 thanksMichael Link to comment https://forums.phpfreaks.com/topic/27971-syntax-questions/ Share on other sites More sharing options...
doni49 Posted November 21, 2006 Share Posted November 21, 2006 www.php.net/objectwww.php.net/class Link to comment https://forums.phpfreaks.com/topic/27971-syntax-questions/#findComment-127945 Share on other sites More sharing options...
kenrbnsn Posted November 21, 2006 Share Posted November 21, 2006 Those references are fine for the '->', but not for "=>" which is used with arrays.Ken Link to comment https://forums.phpfreaks.com/topic/27971-syntax-questions/#findComment-127949 Share on other sites More sharing options...
CheesierAngel Posted November 21, 2006 Share Posted November 21, 2006 The $stuff->something or $stuff->something() are used when programming with classes.[code]<?phpclass 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 More sharing options...
doni49 Posted November 21, 2006 Share Posted November 21, 2006 [quote author=kenrbnsn link=topic=115756.msg471412#msg471412 date=1164123761]Those references are fine for the '->', but not for "=>" which is used with arrays.Ken[/quote]Sorry I guess I read it too quickly. Link to comment https://forums.phpfreaks.com/topic/27971-syntax-questions/#findComment-127955 Share on other sites More sharing options...
kenrbnsn Posted November 21, 2006 Share Posted November 21, 2006 [quote]The "=>" sign is only used while initializing arrays[/quote]It is also used in a foreach statement to assign each value to it's key:[code]<?phpforeach ($ary as $key => $value)?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/27971-syntax-questions/#findComment-127970 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.