Register and join over 40,000 other developers!
Recent Topics
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

2 replies to this topic
#1
Posted 13 April 2012 - 12:01 AM
Please anyone, check this out and do tell me what i did wrong
unction add($number1,$number2)
{
$num1=$number1;
global $num1;
$num2=$number2;
global $num2;
return $total;
$total=$num1 + $num2;
}
$total2=add(10,10)
echo 'The result of additional between'.$num1.'and'.$num2.'is'.$total2;
?>
the output from this is Parse error: syntax error, unexpected T_ECHO in C:\xampp\htdocs\Codes\function.php on line
and in my case, line 68 is pertained to echo 'The result of additional between'.$num1.'and'.$num2.'is'.$total2;
i could find anything wrong here.
function test()
{
echo ' My name is Farhan' . ' and I am 21 ';
}
echo 'This is about my self which states there that '.test().'</br>' ;
and the output is: My name is Farhan and I am 21 This is about my self which states there that
how can i make it This is about my self which states there that My name is Farhan and I am 21?
what did i do wrong?
unction add($number1,$number2)
{
$num1=$number1;
global $num1;
$num2=$number2;
global $num2;
return $total;
$total=$num1 + $num2;
}
$total2=add(10,10)
echo 'The result of additional between'.$num1.'and'.$num2.'is'.$total2;
?>
the output from this is Parse error: syntax error, unexpected T_ECHO in C:\xampp\htdocs\Codes\function.php on line
and in my case, line 68 is pertained to echo 'The result of additional between'.$num1.'and'.$num2.'is'.$total2;
i could find anything wrong here.
function test()
{
echo ' My name is Farhan' . ' and I am 21 ';
}
echo 'This is about my self which states there that '.test().'</br>' ;
and the output is: My name is Farhan and I am 21 This is about my self which states there that
how can i make it This is about my self which states there that My name is Farhan and I am 21?
what did i do wrong?
#2
Posted 13 April 2012 - 12:44 AM
Please use the code tags when posting code (the <> icon on the lower styling bar).
It seems you have a type in function (I have never heard of a unction) and are missing a semi colon (a
to end the add() function.
Anyway:
EDIT: Holy lord of Notch! I have five hundred and thirty two posts! I didn't even know I had more than two hundred
.
It seems you have a type in function (I have never heard of a unction) and are missing a semi colon (a

Anyway:
<?php function add($number1,$number2) { $num1=$number1; global $num1; $num2=$number2; global $num2; return $total; $total=$num1 + $num2; } $total2=add(10,10); echo 'The result of additional between'.$num1.'and'.$num2.'is'.$total2; ?>Try that.
EDIT: Holy lord of Notch! I have five hundred and thirty two posts! I didn't even know I had more than two hundred

Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).
#3
Posted 13 April 2012 - 12:51 AM
let's fix the easy one first
instead of using echo in the function to display "My name is Farhan and I am 21", use return instead something like this
let's jump into the other one
first you have to initialize the global variable first before assigning a value into them.
Second remember to put the return statement at the very end of the code always, except if there is a control statement like IF/ELSE
because when a return statement was triggered the program will ignore the operation below that return statement and forgot to add a semicolon into your $total2 line
try this one
and here's a shorter code for you
function test() { echo ' My name is Farhan' . ' and I am 21 '; } echo 'This is about my self which states there that '.test().'</br>' ;
instead of using echo in the function to display "My name is Farhan and I am 21", use return instead something like this
function test()[/size] { return ' My name is Farhan' . ' and I am 21 '; } echo 'This is about my self which states there that '.test().'</br>' ;
let's jump into the other one
function add($number1,$number2) { $num1=$number1; global $num1; $num2=$number2; global $num2; return $total; $total=$num1 + $num2; } $total2=add(10,10) echo 'The result of additional between'.$num1.'and'.$num2.'is'.$total2; ?>
first you have to initialize the global variable first before assigning a value into them.
Second remember to put the return statement at the very end of the code always, except if there is a control statement like IF/ELSE
because when a return statement was triggered the program will ignore the operation below that return statement and forgot to add a semicolon into your $total2 line

try this one
function add($number1, $number2) { global $num1; global $num2; $num1 = $number1; $num2 = $number2; $total = $num1 + $num2; return $total; } $total2 = add(10,10); echo 'The result of additional between'.$num1.'and'.$num2.'is'.$total2;
and here's a shorter code for you

function add($number1, $number2) { $total = $number1+ $number2; return 'The result of additional between'.$number1.'and'.$number2.'is'.$total; } echo add(10,10);
Life has no CTRL+Z
Never Forget To HIT "LIKE" If I Helped
Never Forget To HIT "LIKE" If I Helped
Also tagged with one or more of these keywords: syntax, syntax error
Language Forums →
HTML, CSS and Javascript →
Syntax and Reference Error?Started by Tonyobyo , 10 Jun 2016 ![]() |
|
![]()
|
||
![]() What language is $("#my_table").sortr();Started by ZOOM , 09 Sep 2014 ![]() |
|
![]()
|
||
Tutorial Forums →
Other Programming Tutorials →
Video Tutorials →
[TYPO3/Eclipse] Add TYPO3 syntax highlighting in EclipseStarted by Charny , 09 Aug 2014 ![]() |
|
![]()
|
||
![]() What I'm I doing wrongStarted by hard1010lad , 19 May 2014 ![]() |
|
![]()
|
||
Language Forums →
Visual Basic →
XML Query AssistanceStarted by Whitey , 10 Mar 2014 ![]() |
|
![]()
|
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download