Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > PHP Forum

PHP Forum Use this forum to discuss all aspects of PHP Development. PHP is a server-side, cross-platform, HTML embedded scripting language that lets you create dynamic web pages.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-27-2006, 10:39 AM
falco85 falco85 is offline
Programmer
 
Join Date: Apr 2006
Posts: 105
Rep Power: 10
falco85 is on a distinguished road
Default Return functions

Is there any way to make a function which returns more than one value (true or false) and (the array)?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-27-2006, 12:32 PM
Thomas Thomas is offline
Newbie
 
Join Date: Sep 2006
Posts: 15
Rep Power: 9
Thomas is on a distinguished road
Default

Have you tried using an array to pass each argument back?

function fn($arg1, $arg2)
{
return array($arg1, $arg2);
}

Use the List function to set variables after calling your function like so:

list($var1, $var2) = fn(1, 2);

This will simply set $var1 to '1' and $var2 to '2'

Last edited by Thomas; 09-27-2006 at 12:58 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-27-2006, 08:43 PM
Nightracer's Avatar   
Nightracer Nightracer is offline
Programmer
 
Join Date: Jun 2006
Posts: 131
Rep Power: 9
Nightracer is on a distinguished road
Default

Why not pass it by reference?

PHP Code:
$variable myFunc($v1, &$v2); 
This way you get $variable back and whatever is done to $v2 in the function changes the variable outside of the function.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-29-2006, 07:02 PM
Chan Chan is offline
Programming Professional
 
Join Date: Jun 2006
Posts: 205
Rep Power: 10
Chan is on a distinguished road
Default

What is pass by reference?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-29-2006, 10:36 PM
Thomas Thomas is offline
Newbie
 
Join Date: Sep 2006
Posts: 15
Rep Power: 9
Thomas is on a distinguished road
Lightbulb

Pass by reference essentially sets a pointer to the original variable's memory location so that you can "pass" the variable on to the function without needing to create a duplicate of the variable. And when the function changes the variable it also changes outside the function since the function is changing the same memory location that the original variable also points too.

For example

PHP Code:
<?php
//pass variable $a by reference
function foo(&$var)
{
//add 1 to $var which essentially adds 1 to $a since $var points to $a's memory location
   
$var++;
}

$a=5;
foo($a);
// $a is 6 here
?>
This example was taken off the php.net site see more information here.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A simple TicTacToe game Zunone C and C++ 1 08-16-2007 12:01 PM
Dictonary Program programmer 101 Java Help 9 07-01-2007 02:39 PM
null exception problem connor7777 C# Programming 2 03-28-2007 12:37 PM
Flex, bison multifunction calculator annatsos C and C++ 1 01-04-2007 07:00 AM
Get and Set Functions Chan C# Programming 3 08-25-2006 12:44 PM


All times are GMT -5. The time now is 05:07 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads