Adi CSS Tools for PHP is a very intuitive tool for prepare CSS strings directly in PHP code.
Preferred way to install is with Composer.
Install this library using composer:
$ composer require adilab/css
Usage of Css class. Online demo.
require('vendor/autoload.php');
use Adi\Css\Css;
$css = new Css('display: inline-block;margin-right: 10px;min-width: 150px;');
$css->set('width: 20px');
$css->set('color', '#ff0000')->set('background-color: #ccc');
echo "<div style='{$css}'>Hello world</div>";