I was just wondering, how can I improve this code?
$count = count($data['tags']);
if($count > 3)
{
$hashtags = implode(',', array_slice($data['tags'], 0,3));
}
elseif($count !== 0)
{
$hashtags = implode(',', array_slice($data['tags'], 0,$count));
}
else
{
$hashtags = 'data';
}
Btw, wasn’t there a section on stackoverflow to ask for possibles code improvements? Can’t find it in the footer links
EDIT:
By improvement I was mainly thinking about shorthand and than I was looking for a different approach for the same thing (just to learn something new) Thanks for the help guys!
Not tested since I don’t code in PHP, but how about this?