php: Need little help in Coding


 
Thread Tools Search this Thread
Top Forums Programming php: Need little help in Coding
# 1  
Old 09-26-2012
php: Need little help in Coding

I have been starting

What wrong with this? ive been staring at it but not coming up with anything

im getting syntax error, unexpected T_RETURN where it says " return $result; "

Code:
<?php



function add_subtract ($value1, $value2) {
$add = $value1 + $value2;
$subtract = $value1 - $value2;
$result = array($add, $subtract)
return $result;
}

$resultArray = add_subtract (10,5);
echo "Add: ".$resultArray[0];
echo "Subract: " .$resultArray[1];

?>

Thanks in advance

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by radoulov; 09-26-2012 at 09:20 AM..
# 2  
Old 09-26-2012
Is this bash or alike? Looks like ... post in other forum (shell scripting...) and read the man page, esp. for function definition etc., array creation and assignment, variable assingnment and expansion, arithmetic evaluation and expansion. I think this does what you had in mind:
Code:
function add_subtract ()
        {
         add=$(( $1 + $2 ))
         subtract=$(($1 - $2))
         result=( $add $subtract )
         echo ${result[@]}
        }

resultArray=( $(add_subtract 10 5) )
echo "Add: " ${resultArray[0]}
echo "Subtract: " ${resultArray[1]}

P.S.: use code tags for your scripts etc...
# 3  
Old 09-26-2012
Hi.

Missing semi-colon:
Code:
#!/usr/bin/php
<?php

#  @(#) s1      Demonstrate function call.
// @(#) s1      Demonstrate function call.

print "\n";
print " Hello, world from php.\n";
print "\n";

function add_subtract ($value1, $value2) {
$add = $value1 + $value2;
$subtract = $value1 - $value2;
// $result = array($add, $subtract)
$result = array($add, $subtract);
return $result;
}

$resultArray = add_subtract (10,5);
echo "Add: ".$resultArray[0],"\n";
echo "Subract: " .$resultArray[1], "\n";

?>

producing:
Code:
% ./s1

 Hello, world from php.

Add: 15
Subract: 5

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Coding the cron

how to write a cron that runs for every 2 minute * * * * * emp.sh but it is executing for every minutes. how can i make it to run for only 10 times for in a day (4 Replies)
Discussion started by: azherkn3
4 Replies

2. Windows & DOS: Issues & Discussions

Need help with coding

HI, Can some one guide me how to make changes to the script below so that it can load the history of a program to IT server ? Format of data: YYYYMMDD065959.dsk.log YYYYMMDD235959.dsk.log currently both are loaded together. Need to separate them as above format. Thanks in advance. ... (2 Replies)
Discussion started by: crazydude80
2 Replies

3. Shell Programming and Scripting

Need help with coding

HI, Can some one guide me how to make changes to the script below so that it can load the history of a program to IT server ? Format of data: YYYYMMDD065959.dsk.log YYYYMMDD235959.dsk.log currently both are loaded together. Need to separate them as above format. Thanks in advance. ... (1 Reply)
Discussion started by: crazydude80
1 Replies

4. AIX

need help for coding this logic

contact me on <email address deleted> or <email address deleted> (1 Reply)
Discussion started by: suprithhr
1 Replies

5. Programming

where i get coding for networking in C?

hai, this is nagalakshmi. i have a question in Unix C. i need the coding for the file transfer and simulation of protocols in C where i get the coding? (2 Replies)
Discussion started by: xpertlakshmi
2 Replies

6. UNIX for Advanced & Expert Users

can I use this coding

I apologise because I had pasted this question in the newbies forum first (because i am a bit of a newbie) but thought it might be better suited in here if i have to sepearate parameters can I use this syntax especially the or part (||) and is this correct if (6 Replies)
Discussion started by: w33man
6 Replies
Login or Register to Ask a Question