1

Someone show me how I can write this line of codes in short.

if($x[$key_url] == $last_news)          
{
    $new_next = $first; 
}
else{
    $new_next = $x[$key_url + 2];   
}
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103

2 Answers2

2

Using ternary operator it becomes:

$new_next = $x[$key_url] == $last_news ? $first : $x[$key_url + 2]
u_mulder
  • 54,101
  • 5
  • 48
  • 64
2

Here is the example

$new_next = $x[$key_url + 2];   
if($x[$key_url] == $last_news) {
   $new_next = $first; 
}

Or

 $new_next =  ($x[$key_url] == $last_news) ? $first : $x[$key_url + 2];
Aram Grigoryan
  • 740
  • 1
  • 6
  • 24