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; "

<?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

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:

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...

Hi.

Missing semi-colon:

#!/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:

% ./s1

 Hello, world from php.

Add: 15
Subract: 5

Best wishes ... cheers, drl