-2

Why do I get error in syntax from the code below:

<?php>
function wpai_package($price, $pack) {
    if($pack!=' '){
        return ($pack * $price);
    } else {
        return($price)
    }
}
?>

Syntax error unexpected'}' on line 8

I want to say if the pack IS NOT EMPTY (null) then price x pack otherwise price.

Thanks

Barmar
  • 741,623
  • 53
  • 500
  • 612
babi mc
  • 1
  • 6

3 Answers3

1

you missed an ; near return

 <?php
function wpai_package($price, $pack) {
   if(!empty($pack)){
     return ($pack * $price);
   } else {
     return($price);

   }
}
?>
AmalJo
  • 106
  • 9
0

Change Your Code To

<?php


function wpai_package($price, $pack) {

    if(!empty($pack))
    {
        return ($pack * $price);
    } else {
        return $price;
    }
}

wpai_package(2,45);

Live Demo

And Also You Should Have to LEarn Return At here http://php.net/manual/en/function.return.php

TarangP
  • 2,711
  • 5
  • 20
  • 41
0

In the first line you added a > after <?php which has to be removed.

In line 7 the semicolon is missing at the end of the line.

Rico
  • 107
  • 6