Jump to content

sending variables back to parent function.


UrbanDweller

Recommended Posts

Hey ive been wanting to know how to make a function call another function which will then create a variable which i can send back to first function where i can use it.

 

I tried somthing like this

<?php
a();
function a($wall)
{
	b();
	echo $wall;
}
function b()
{
	$wall = "test";
	#a($wall);
}
?>

 

Thats what i tried but ofcourse didnt work, how would i go about doing this?

 

Thanks.

Functions RETURN the results that they produce.

 

The point of functions are they (optionally) accept call time parameters, produce some useful result, and then return that result at the point that they were called. You can either assign the returned result to a variable or use it as a parameter in another function call or use it as a value in a language construct.

<?php
a();
function a()
{
	// use the returned value as a parameter/value in another function/language construct
	echo b();

	// or assign the returned value to a variable
	$c = b();

	echo $c;

}
function b()
{
	return "test"; // ... code that produces some useful result and returns it to the calling code
}
?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.