473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sharing variables between functions

Hi all

It's me again.. I have a variable to which i am assigning a value in one function. I have to use the variable with the same value assigned in another function. How can I do this. I've tried to portray this in the following codes

Thanks.


[PHP]Function x
{
$a =25
}

Function y
{
If ($a=25)
sql_insert();
}[/PHP]
Jul 2 '07 #1
3 3440
ak1dnar
1,584 Expert 1GB
Hi all

It's me again.. I have a variable to which i am assigning a value in one function. I have to use the variable with the same value assigned in another function. How can I do this. I've tried to portray this in the following codes

Thanks.


[PHP]Function x
{
$a =25
}

Function y
{
If ($a=25)
sql_insert();
}[/PHP]
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. function FuncOne(){
  3. $toFuncTwo = 25;  // CHANGE THIS
  4. return $toFuncTwo; 
  5. }
  6.  
  7. function FuncTwo($ReturnedValuefromFuncOne){
  8.     if($ReturnedValuefromFuncOne==25)
  9.     {
  10.     $Msg = 'True';
  11.     }else
  12.     {
  13.     $Msg = 'False';
  14.     }
  15. return $Msg;
  16. }
  17. $returnValue =FuncOne();
  18. print FuncTwo($returnValue);
  19. ?>
  20.  
Jul 2 '07 #2
ronnil
134 Expert 100+
you could also make a "global" variable

[PHP] $var = '';

function funcOne()
{
$var = 25;
}

function funcTwo()
{
echo $var;
}

echo $var; //outputs an empty string
funcOne();
funcTwo(); //outputs 25
[/PHP]
but i like ajaxrands solution more, since one rarely want to use global variables unless unavoidable :)
Jul 2 '07 #3
pbmods
5,821 Expert 4TB
Changed thread title to better describe the problem.
Jul 2 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Antony Sequeira | last post by:
Hi I needed to share some configuration information across requests. The most straightforward way would be code it in a php file and include it in every other script. The problem with this...
42
by: Dan | last post by:
Hello, I have trouble with class calling. I am calling getvolume() with succes in the function CreateCircle but it do not want to call it in ShowCircle() function. I am staying in the same...
7
by: Michael | last post by:
Hi newsgroup, as the subject indicates I am looking for an advice using global variables. I am not if this problem is more about style then C. If its wrong in thi group, sorry. So I have a...
3
by: darrel | last post by:
This is something I should know, but I don't. Say I have this: Function dim variable1 dim variable2 do stuff with the variables
3
by: Selden McCabe | last post by:
I have an old ASP project, and I'm adding some functionality in ASP.Net. I stuff some information into Session variables in the ASP page, then redirect to the ASP.Net page. But when I pull up...
1
by: Terry Olsen | last post by:
What is the best practice for sharing variables across modules in the same project? I'm doing a console app with different modules for different functions (file i/o, sql commands, string...
1
by: Joe | last post by:
While I understand that Server Side Includes still work, I realize it's not the best practice for sharing code such as a common set of includes between screens. In ASP.NET I've already built...
1
by: David Belohrad | last post by:
Dear All, could someone give a hint? I'd like to share the resources as follows: A shared class which works as counter of number of shared resources: class Shared { public: Q_PCBShared()...
6
by: awhan.iitk | last post by:
I have a set of variables that I want to share across mulitple c++ files. I was using the extern method so far. Is there any other way to do the same. The variables are not constants and I get the...
45
by: =?Utf-8?B?QmV0aA==?= | last post by:
Hello. I'm trying to find another way to share an instance of an object with other classes. I started by passing the instance to the other class's constructor, like this: Friend Class...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.