SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Perth W.A.
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Understanding php syntax

    Can someone please explain the symbols -> and => in the following code?

    Any help appreciated.

    if ($this->params->get('loadMootools')) {
    $this->_scripts = array_merge(array($template_baseurl . '/lib/js/mootools.js.php' => 'text/javascript'), $this->_scripts);
    unset($this->_scripts[$this->baseurl . '/media/system/js/mootools.js']);
    }

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    -> is an object reference.

    $this->_scripts[stuff] = "Go to the object $this, and find the _scripts property of it. In this case, that property is an array, and so it calls for a specific index of that array.
    $this->params->get('loadMootools') is actually "Go to the object $this, and find the params property of it. This property is apparantly an object itself, with a method get(), which is called with a string parameter (loadMootools)

    => is used as a key-value pairing identifier.

    in this case, it's in an array definition, assigning the value 'text/javascript' to the key $template_baseurl.'/lib/js/mootools.js.php'. You also often see this notation in foreach statements (foreach ($array AS $key => $value))
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    -> is a class assignment:
    http://us.php.net/manual/en/language...properties.php

    => is assigning a value to an index:
    http://us.php.net/manual/en/function.array.php

    Edit: did not see the above post when I was replying. Much more detail provided.

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Perth W.A.
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Guys,

    I think I'm starting half way up the ladder - need to go back to basics - thanks for the links


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •