1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Pushing From Input To A Function?

Discussion in 'PHP' started by gobbly2100, Apr 14, 2009.

  1. #1
    Hey all,

    I am making a simple little script to work out fuel econemy and I don't know how I can push the form data to a function which will make some calculations and then return it to the page.

    How can I use the post data and then send it to a function as arguments?

    I hope that makes sense, any help is much appreciated!
     
    gobbly2100, Apr 14, 2009 IP
  2. zendowind

    zendowind Banned

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    <?php
    $data = $_POST['data']; // name of your field
    function returnme($argument) {
          return $argument;
    }
    echo returnme($data); // we pass our $data as an argument
    ?>
    
    PHP:
     
    zendowind, Apr 14, 2009 IP
  3. jimbursch

    jimbursch Peon

    Messages:
    33
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Might make more sense to you like this:

    <?php

    function returnme($argument) {
    return $argument;
    }

    $data = $_POST['data']; // name of your field
    echo returnme($data); // we pass our $data as an argument
    ?>

    Also, when you define your function, you can set default values for the variable:

    function returnme($argument=0) { // sets 0 as the default if no value is passed to the function
    return $argument;
    }
     
    jimbursch, Apr 14, 2009 IP
  4. gobbly2100

    gobbly2100 Banned

    Messages:
    906
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    gobbly2100, Apr 14, 2009 IP
  5. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #5
    You might want to round numbers off to three digits.

    Peace,
     
    Barti1987, Apr 14, 2009 IP