473,383 Members | 1,846 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,383 software developers and data experts.

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 1566

"Jason" <jw*******@courtesymortgage.com> wrote in message
news:10*************@corp.supernews.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.supernews.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>Untitled Document</TITLE> <META HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=iso-8859-1">
</HEAD>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<?php
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
function multiply($number_from_box1,$number_from_box2)
{
$number = $number_from_box1 * $number_from_box2;
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
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...
5
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...
1
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...
3
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...
4
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):...
3
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...
4
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...
8
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...
13
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.