Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

PHP - Switch case example

0 votes
9 views
added Mar 7 in PHP by LC Marshal Captain (23,680 points)
edited Aug 9 by LC Marshal
<?php
function translate_lease_term( $lease_term_id = NULL ){
  $lease_term_id = trim( $lease_term_id );
  if ( !isset( $lease_term_id ) || $lease_term_id === '' )
    return FALSE;

  switch ( $lease_term_id ) {
    case 'fh':
    return 'Freehold';
    case '999lh':
    return '999 years';
    case '99lh':
    return '99 years';
    case '30lh':
    return '30 years';
    case '60lh':
    return '60 years';
    case 'lh':
    return 'Leasehold';
    case 'mrl':
    return 'Malay Reserved Land';
    default:
    return FALSE;
  }

}
?>

 

1 Response

0 votes
responded Aug 9 by LC Marshal Captain (23,680 points)
// switch case for time update
<?php
  $popularList = json_decode($popularListJson);
  foreach($popularList as $news):
  $ago = $news->days_ago;
  switch ($ago){
    case 0:
      $days_ago = 'Today';
      break;
    case 1:
    $days_ago = $ago.' day ago';
      break;
    default:
    $days_ago = $ago.' days ago';
  }			
?>

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...