Is there a shorter way to accomplish the following?
<?php
$arr = [];
// ...
if(isset($arr['key']))
$arr['key'] += 10;
else
$arr['key'] = 10;
?>
Is there a shorter way to accomplish the following?
<?php
$arr = [];
// ...
if(isset($arr['key']))
$arr['key'] += 10;
else
$arr['key'] = 10;
?>
Use the ternary operator:Try it
<?php
$arr = [];
// ...
$arr['key']= isset($arr['key'])?($arr['key']+10):10;