Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-24-2003, 04:46 PM   #1 (permalink)
Admin
$_['Your_Mom'];
 
Admin's Avatar
 
Join Date: May 2002
Location: Santee
Posts: 627
Admin is on a distinguished road
writing basic functions?

i need a tutorial on writing PHP functions. anyone know of anything good?
__________________


Urban Clothing
Admin is offline   Reply With Quote
Old 11-24-2003, 05:18 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,505
sde is on a distinguished road
PHP Code:
<?
function sayWhat()
{
  return 
"What";
}

echo 
sayWhat();

function 
saySomething($string)
{
  return 
$string;
}

echo 
saySomethingElse("something");

function 
doSomething($string1,$string2,$string3,$string4)
{
  return 
$string1 " " $string2 " " $string3 " " $string4;
}

echo 
saySomethingElse("Matt","is","1337","Coder");

function 
add($x,$y)
{
  return 
$x $y;
}
echo 
add(2,3);  // echos 5
?>
are you kidding matt?
__________________
Mike
sde is offline   Reply With Quote
Old 11-25-2003, 08:25 AM   #3 (permalink)
Admin
$_['Your_Mom'];
 
Admin's Avatar
 
Join Date: May 2002
Location: Santee
Posts: 627
Admin is on a distinguished road
i want to know all the rules when writing functions dude. sometimes i get stuck on something simple and it would be nice to just know exactly what is going on help figure some **** out.
__________________


Urban Clothing
Admin is offline   Reply With Quote
Old 11-25-2003, 12:33 PM   #4 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
PHP Code:
<?
/*
 * global variables.
 */
$x 5;
function 
foo()
{
  global 
$x;
  echo 
$x."\n";
}
foo(); // prints 5

/*
 * default values
 */
function bar($y "BAR")
{
  echo 
$y."\n";
}
bar(); // prints 'BAR'

/*
 * passing by reference
 */
function ref(&$z)
{
  echo 
$z."\n";
}  
$z "dude";
ref($z); // prints "dude" without making a copy of the string

/*
 * function pointers
 */
function asdf()
{
  echo 
"hi\n";
}
$fx "asdf";
$
$fx(); // prints "hi"
?>
joe_bruin is offline   Reply With Quote
Old 11-25-2003, 12:43 PM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,505
sde is on a distinguished road
wow, had no idea you could pass by reference in php.

thanks joe
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can anyone recommend a very basic message board? Epsilon PHP 2 02-29-2004 08:02 AM
Basic, not visual platjyjim All Other Coding Languages 1 03-01-2003 09:00 AM


All times are GMT -8. The time now is 03:43 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting