SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all, as many here know, I'm new to PHP by only a few months. I've been able to pull from my javaScript experience to pickup on the language rather quickly, but I have a couple easy questions about operators that I can't seem to find an answer to.

    The first one is =>. I see this used in assigning values in arrays.

    Code:
    array("name" =>"Joe");
    My question is, is this an assignment opperator, and if so, what makes it different than saying "name"="joe"? What all situations is the => operator used in?

    The other one is ->. I see this used simularly in examples like

    Code:
    function printinfo(){
    bla bla bla
    $this->printinfo("Joe", "Eliason", "HotDog");
    }
    Again, is this an asignment operator, or just specific to this type of situation?

    Also, while I'm on simple questions...I saw somewhere here a header() script that will load a new page after a given number of seconds, allowing a page to load so a visitor could see it and then redirect them to another page. I've been doing this using javascript "replace.location()", but I'd like to know the other way if anyone knows.
    Joe Eliason
    Just a dog learnin' PHP from cat.

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Question 1:

    This operator means make the array key "name" and the value for that key "Joe".
    PHP Code:
    array("name" => "Joe"); 
    Question 2:
    This is used in class definitions when calling on a method or var of the class from within it self.
    PHP Code:
    $this-> 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Example 1...I understand what it is doing, but is it only used in arrays? I guess that's my question.

    Example 2...So this is the only place where this is used as well? This one I do not understand.
    Last edited by HotDog; Mar 13, 2001 at 12:51.
    Joe Eliason
    Just a dog learnin' PHP from cat.

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let me try on #2 again. Let's say you have a regular old function to print a string in upper case.


    PHP Code:
    function go_up($str) {
    return 
    strtoupper($str);
    }

    print 
    go_up("Joe Eliason"); 
    This works great, but lets say that function is contained within a class.

    PHP Code:
    class Guestbook {
    var 
    $name;
    var 
    $email;
    function 
    Guestbook() {
    global 
    $name$email;
    //Set the global vars name and email to class level vars so they can be called from within the class without using global
    $this->email $email;
    $this->name $name;

    //Call the method print_name()
    $this->print_name();

    }

    function 
    print_name() {
    print 
    $this->name;
    }



    I really hope that helps. Sorry I often have a hrd time delivering what is in my brain to the screen. Check out these tutorials.

    [url="http://www.phpbuilder.com/columns/rod19990601.php3"]
    class article on phpbuilder[url]

    [url="http://www.devshed.com/Server_Side/PHP/BackToClass/"]
    class article on devshed[url]
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I understand a little more on #2. I understand what a class is, but I haven't worked with them at all in PHP as of yet, so the syntax is still a little fuzzy. I'll take a look at the tutorials.

    Do you happon to know the answer to the header() question?? I know I saw it here in a post, but I can't find it. I've looked for a couple of days. I should have wrote it down when I first saw it.
    Joe Eliason
    Just a dog learnin' PHP from cat.

  6. #6
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    PHP Code:
    header("refresh:5;URL=redirect_url_here.html"); 
    Where '5' is the number of seconds to delay, and 'redirect_url_here.html' is the filename/URL to load after the specified delay.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  7. #7
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Again, thank you kev and fred. The tutorials on classes at the devshed were very good. Since I use classes all the time in CSS the consept was easy to grasp. I see many areas in my current project where I could have/can use them.

    It's just a little frustrating at times because I only know/understand pockets of php, so I find myself trying to fix all my problems with what I do know, when many times there is a better way of doing it, I just don't know it. There are many times where I understand what something is doing, I just don't know the reason why it is doing it the way it is. Like my two original questions. I'm just so use to javascript that I expect php to follow the same rules sometimes I guess. It's like learning Spanish after only speaking English for so many years.

    Anyway, thanks again for the info.
    Joe Eliason
    Just a dog learnin' PHP from cat.


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
  •