Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 11th, 2005, 02:10 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 117
Thanks: 0
Thanked 2 Times in 2 Posts
Default Function

Hi
I try to use Function and Instead of useing global $var I try to use something like function($var)
Here is my code

test.php
////////////
<?
$var = 'Hi';

function load($var)
{
  echo $var;
}
?>

When try to see the page I'm getting that worning:
Warning: Missing argument 1 for load()......

Before I used something like this:

////////
<?
$var = "hi";
function load()
{
  global $var;
  echo $var;
}
?>

and it works.

Can anyone please tell me whats wrong with my first example (test.php)

Thanks
Regards
Mani_he

 
Old May 14th, 2005, 10:10 AM
Authorized User
 
Join Date: Jan 2005
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The purpose of a function is to do a certain function at the time its called. like the following function:

function load(){
echo "i like this";
}

You put this function in your header or on top of the page and then you can call it down anywhere in your code and it'd echo "i like this."

However, functions can have arguments. so something like

function load($var1, $var2){
echo $var1;
echo $var2;
}

to use this you can define $var1 and $var2 in your page down the line and use it this way:

$var1 = "this is Variable 1";
$var2 = "this is variable 2";

load($var1, $var2);

Now you don't have to use the same name for the variables in the page as you used in the function it could be:

$age1 = "my age is 1";
$age2 = "my age is 2";

load ($age1, $age2);

and that'd give you the same result.



----------------
Never bother to learn something not knowing which does not do you any harm, and never neglect to learn something whose negligence will increase your ignorance - Imam Jafar Sadeq





Similar Threads
Thread Thread Starter Forum Replies Last Post
function keyvanjan ASP.NET 2.0 Professional 1 September 19th, 2007 10:22 AM
How to use Function akumarp2p SQL Server 2000 1 May 28th, 2007 05:04 AM
send variable in function to another function schoolBoy Javascript How-To 6 March 3rd, 2007 09:16 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
retreive function/Line from macro or function? MikoMax J2EE 0 April 1st, 2004 04:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.