title: How to Properly Write User Defined Function in PHP?
body: <p>I have a php file named priceAPI.php that gives me price of gold in difference currencies.  For example $price_usd is for price in US Dollar and likewise $price_aed is for price in UAE Dirhams and so on.
  I am trying to write a function that based on a string defined by a user would fetch the price that relates to user's choice of currency:</p>
  
  <p>My function looks like this:</p>
  
  <pre><code>function getPrice($user_currency) {
  require_once('priceAPI.php');
  if($user_currency == 'usd') {
  
  $price = $price_usd;
  return $price;
  
  }elseif ($user_currency == 'aed'){
  $price = $price_usd;
  return $price;
  
  }
  
  $user_currency = 'aed';
  
  echo getPrice($user_currency);
  </code></pre>
  
  <p>When I try to call the function it doesn't give any results whereas if I echo $price_usd or $price_aed it does give me the price.</p>
  
  <p>Any help as to how I can make this function work will be appreciated.  Thanks</p>