Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts

    Learning about Function, got a question.

    I knew from my java past that you can make a function, and call it when ever needed. So i looked it up, and PHP has that too. Heres my question.

    PHP Code:
    create_function('$x,$y'' print"This is a test!"; '); 
    What is the $x $y for? How do i use them? How do i know what to put there extra.

    Also. How can i later call this function? Would:
    PHP Code:
    function($x); 
    do it? Cant seem to find a simple tut on this.
    If I'm postin here, I NEED YOUR HELP!!

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    function function_name($x) {
    return 
    $x;
    }
    That's a basic function, but that's how you set it up. And when you call it can look like:

    PHP Code:
    <?php
    function_name
    ("hi!"); // returns hi!
    ?>
    PHP Code:
    <?php
    $y 
    "hi!";
    function_name($y); // also returns hi!
    ?>

  • #3
    New Coder
    Join Date
    Jun 2002
    Location
    Colorado
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perhaps you might take a look at this link:
    http://www.phpfreaks.com/phpmanual/p...-function.html
    -Sk8er9547

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts
    if someone could explain this for me. I've read the PHP, Zend, all that stuff. And none of them use non-technical language to explain what anything is. I know the fist variable is the string arg, but i dont know what that is.

    Basicly, im looking for a quick, Functions for dummies tut.

    Sorry for not understanding this. Thanks for your help.
    If I'm postin here, I NEED YOUR HELP!!

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    look again at Kurashu's post , thats a simple PHP function , and if you look at the manual at www.php.net (better still download it) there is more information than you need, including a whole section for functions

    create_function() does indeed create a function but makes it at runtime which is quite different from `normal` static functions which you will be using 99% of the time, I would suggest getting used to normal functions before looking at dynamic ones.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #6
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Ultragames
    if someone could explain this for me. I've read the PHP, Zend, all that stuff. And none of them use non-technical language to explain what anything is. I know the fist variable is the string arg, but i dont know what that is.

    Basicly, im looking for a quick, Functions for dummies tut.

    Sorry for not understanding this. Thanks for your help.
    $args could be anything, it could be $look_at_me_i_am_a_variable_and_i_contain_stuff_but_my_name_is_insanely_long. It just tells the function: as far as you are concerned, anything in this postion is named $varaible_name. So, going back to my previous post:

    PHP Code:
    <?php 
    function function_name($x,$y,$z) { 
    print 
    "$y <br>\n $z <br>\n $x <br>\n";

    ?>
    That function will print the contents of $x, $y, and $z. How you want to place the contents of them is all up to you; variables, hardcoding it, or a definition (are they allowed in functions?) it is up to you. You can use (almost) any langauge construct in your function. Functions are just another way of oragnizing your code, so be creative and explore them; and, if you have a problem, that is what this board is for.


  •  

    Posting Permissions

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