Transforming an array to CssClasses

1use Illuminate\Support\Arr;
2 
3$array = ['p-4', 'font-bold' => $isActive, 'bg-red' => $hasError];
4 
5$isActive = false;
6$hasError = true;
7 
8$classes = Arr::toCssClasses($array);
9 
10/*
11 * 'p-4 bg-red'
12 */

Tip given by @dietsedev

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord