jeudi 28 janvier 2016

What is better if else or only if to return a value inside a funciton and why?

Hi a am hesitant to ask this but I need some advise about this sample code and what is better between the two function below.

function get_product($productType){
  $product =[];

  if('available'== $productType){
    $product = array('tshirt','pants','polo'); 
  }else if('out_of_stock' == $productType){
    $product = array('short');
  }
  return $product;
}

or

function get_product($productType){
  $product = array('tshirt','pants','polo');

  if('out_of_stock' == $productType){
    $product = array('short');
  }
  return $product;
}

I just want to get the opinion of some programmers.Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire