473,547 Members | 2,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Understanding 'function' question

Hello everyone.
Back with a pretty simple question regarding functions in PHP. Granted,
still learning here and just trying to 'understand' what goes on and how
it works.

Here is a little simple piece of code that I have a question on:

<?php
$number = 50;

function tenTimes()

{
global $number;
$number = $number * 10;
}

tenTimes();
print $number;
?>
This displays 500 in a browser. Simple enough. I just have a question on
the 3rd to last row:

tenTimes();

I know that this is the name of the function, and everything within the
{} is what I defined for the tenTimes function...

But, why is tenTimes(); called at the bottom? I know if I remove it,
'50' is displayed in the page.

For some reason, I seem to having a tough time getting my head wrapped
around this. Could be that I am tired and need a break. :)

Can someone break that down for me? I appreciate it.

Jason
Jul 17 '05 #1
3 1571

"Jason" <jw*******@cour tesymortgage.co m> wrote in message
news:10******** *****@corp.supe rnews.com...
Hello everyone.
Back with a pretty simple question regarding functions in PHP. Granted,
still learning here and just trying to 'understand' what goes on and how
it works.

Here is a little simple piece of code that I have a question on:

<?php
$number = 50;

function tenTimes()

{
global $number;
$number = $number * 10;
}

tenTimes();
print $number;
?>
This displays 500 in a browser. Simple enough. I just have a question on
the 3rd to last row:

tenTimes();

I know that this is the name of the function, and everything within the
{} is what I defined for the tenTimes function...

But, why is tenTimes(); called at the bottom? I know if I remove it,
'50' is displayed in the page.

For some reason, I seem to having a tough time getting my head wrapped
around this. Could be that I am tired and need a break. :)

Can someone break that down for me? I appreciate it.

Jason


I'd like to redirect you to somewhere more academic:
http://www.php.net/manual/en/langref.php

But suffice it to say that the code within a function (defined as above by
saying 'function x() { }') is executed whenever you call them (by saying
'x();'). More than that, it becomes a computer science thingy.

Garp
Jul 17 '05 #2
> I'd like to redirect you to somewhere more academic:
http://www.php.net/manual/en/langref.php

But suffice it to say that the code within a function (defined as above by
saying 'function x() { }') is executed whenever you call them (by saying
'x();'). More than that, it becomes a computer science thingy.

Garp

Hey Garp. I appreciate it. I took a break and grabbed some food and let
my brain rest a bit. I came back and then it seemed to make sense....I
think my brain was working hard and needed some downtime...

I appreciate your help.

Jas
Jul 17 '05 #3
I noticed that Message-ID: <10************ *@corp.supernew s.com> from
Jason contained the following:
Hey Garp. I appreciate it. I took a break and grabbed some food and let
my brain rest a bit. I came back and then it seemed to make sense....I
think my brain was working hard and needed some downtime...

Don't feel bad about it. There is still loads of stuff that makes my
brain hurt.

Functions are little re-useable bits of code. Some times you can pass
values to them to make them give different output. For instance if you
put two text boxes on there to provide input to your function, it
becomes a lot more useful.
<HTML>
<HEAD>
<TITLE>Untitl ed Document</TITLE> <META HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=iso-8859-1">
</HEAD>

<BODY BGCOLOR="#FFFFF F" TEXT="#000000">
<?php
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
function multiply($numbe r_from_box1,$nu mber_from_box2)
{
$number = $number_from_bo x1 * $number_from_bo x2;
return $number;
}
?>
<FORM NAME="form1" METHOD="post" ACTION="">
<P>
<INPUT TYPE="text" NAME="num1"> X <INPUT TYPE="text" NAME="num2">
<INPUT TYPE="submit" NAME="Submit" VALUE="Submit">
</P>
<P><?php

print multiply($num1, $num2);

?>
</P>
</FORM>
</BODY>
</HTML>
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
1803
by: Materialised | last post by:
Hi everyone, I seen the post by Rob Morris, and thought that I would double check that I was using pointers in the correct way. So I written the following string functions to test. I know soem can be iumplimented using the standard libary, but I just wanted to test writing my own functions. They work ok, but I would like some feed back on any...
5
1425
by: Irfan Mumtaz | last post by:
hi, I had posted a question in the group "how to arrange arrays in increasing order" Although i got an answer using IComparable Interface by Harfried ,which is given below. Dim InputArray()() As Integer = _ New Integer()() { _ New Integer() {2, 0, 0}, _ New Integer() {1, 0, 0}, _ New Integer() {6, 0, 0}, _ New Integer() {3, 0, 0} _
1
1989
by: Vaelek | last post by:
Hello, I'm somewhat new to DB programming and have a question. I am now taking over an application that a previous programmer had written and he had made use of the Parameter.Add function for DB2 comman objects. This is what is trying to be done: An sql statement is created that uses ? as value markers. This value is passed into a function...
3
1794
by: Redefined Horizons | last post by:
I'm trying to understand the argument flags that are used in the method table of an extension module written in C. First let me ask this question about the method table. Is it an C array named "PyMethodDef"? Now, onto my questions about the arguments: I see that even when the Python function we are supplying takes no arguments, (the...
4
1749
by: bitshadow | last post by:
I've been working on a link list implementation and I'm driving myself crazy trying to understand something. assuming i have a list and i have the following quasi pseudocode: add(list *head): if(head==NULL) head=newnode else while (head)
3
2138
by: Divick | last post by:
I was reading this section in Bruce Eckel's book which talks about passing and returning large objects ( Chapter 11: References & the Copy-Constructor ), where he explains that how to return big objects / values from functions and the issues involved therein specifically w.r.t. reentrency. He explains that because of reentrency, the object...
4
1619
by: Andrew Taylor | last post by:
Hi, I've been using PHP for a long time, I have designed and developed a number of mid-range systems. I've always used a procedural approach. I fully understand the concept of OO, I know all the basics and I know how to code OO. What I'm having problems with is understanding how to design/architect projects using OO. Can anyone reccomend...
8
1809
by: boki_pfc | last post by:
Hi Everybody, I am looking for an advice on following: I have that "pleasure" of reading C++ codes that have been written by person(s) that have not attended the same C++ classes that I did or have not read the same C++ books that I have read. This kind of people has written some parts of the code that use notations that I am not familiar...
13
1956
by: Sri Harsha Dandibhotla | last post by:
Hello all. I recently came across a function declaration as : char(*(*x()))(); This was not in some code but it was in a C questions thread on some group. I tried to decipher what it returns but couldn't make complete sense out of it. Can someone please explain what this function is supposed to return and expand it step by step. Thanks,
0
7510
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7703
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7463
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7797
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3493
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1923
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1050
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
748
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.