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!
<?php $data = $_POST['data']; // name of your field function returnme($argument) { return $argument; } echo returnme($data); // we pass our $data as an argument ?> PHP:
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; }
Awesome, I worked it out from the replies, thank you guys! If you wanna see it I have it up here: http://www.gobbly2100.com/projects/fuel_econemy/ Thanks!