www.webdeveloper.com
Results 1 to 2 of 2

Thread: Need little help in Coding

  1. #1
    Join Date
    May 2013
    Posts
    119

    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

  2. #2
    Join Date
    Jul 2010
    Location
    /ramdisk/
    Posts
    865
    Quote Originally Posted by noahwilson View Post
    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
    This line:
    Code:
    $result = array($add, $subtract)
    needs a semicolon as a sentinel to PHP (end of the imperative statement). PHP does not use a newline ("\n") character to determine when the end of a statement is. You must ALWAYS add the semicolon.
    I use (, ; : -) as I please- instead of learning the English language specification: I decided to learn Scheme and Java;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles