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.

Link to comment
Share on other sites

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
}
?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.