Home>Article>Backend Development> How to convert nested PHP arrays to CSS rules? (code example)

How to convert nested PHP arrays to CSS rules? (code example)

青灯夜游
青灯夜游 Original
2019-03-18 15:55:53 2915browse

Many aspects of the application can be automated, for example we can use some PHP code (such as using arrays) to generate style sheets. So how to achieve it? The following article will show you how to convert nested PHP arrays into CSS rules and display them in the form of strings. I hope it will be helpful to you.

How to convert nested PHP arrays to CSS rules? (code example)

Let’s take a look at how to convert nested associative arrays into CSS characters.

1. Write a function to convert an associative array into a CSS string

To convert an array into a CSS string in PHP (in SASS or LESS case using rules or simple variables) we will use the following function:

array('property' => 'value')). * 还支持选择器 * 嵌套示例: * array('selector' => array('selector'=>array('property' => 'value'))). * * @return 字符串一个CSS规则字符串。它不包含在