Try:
$name = (strlen($arr['name']) > 12) ? substr($arr['name'],0,12) . "..." : $arr['name'];
This is a conditional assignment. If $arr['name']
is greater than 12 characters, then it truncates it to 12 characters and adds "...". Otherwise, it uses the full name.