How can the css3-php quickly determine whether an item in an array is a single value or a key-value pair?

Source: Internet
Author: User
Thanks to @ joyqi for your attention. Put the actual Code directly as recommended. This is the input data of php that is being tested in CSS3 to expand non-standard attributes as follows: {code ...} process a css file according to the above rules {code ...} you want to automatically expand the writing of non-standard attributes {code .... thanks to @ joyqi for your attention. Put the actual Code directly as recommended.

This is my sample CSS3. Expand the php with non-standard attributes.

The existing input data is as follows:

 Array ('webkit', 'moz', 'ms'), 'border-radius '=> array ('webkit', 'moz', 'O '), 'border-top-right-radius '=> array ('webkit', 'moz' =>'-moz-border-radius-topright ', 'O '), 'border-top-left-radius '=> array ('webkit', 'moz' =>'-moz-border-radius-topleft', 'O '), 'border-bottom-right-radius '=> array ('webkit', 'moz' =>'-moz-border-radius-bottomright', 'O '), 'border-bottom-left-radius '=> array ('webkit', 'moz' =>'-moz-border-radius-bott Omleft ', 'O'), 'border-color' => array ('moz'), 'box-shadow' => array ('webkit ', 'moz ', 'o'), 'transfer' => array ('webkit', 'moz', 'ms', 'O'), 'transform' => array ('webkit ', 'moz', 'ms', 'O '),......); $ _ valuerules = array (// css3 compatible value table is appended to the header 'linear-gradient' => array ('webkit ', 'moz', 'ms', 'O'), 'box' => array ('webkit ', 'moz', 'O '), 'box-shadow' => array ('webkit ', 'moz') ......);?>

Process a css file according to the preceding rules.

.container {   box-shadow: 20px;   transition: box-shadow 2s;   border-top-right-radius: 4px;   border-bottom-left-radius: 4px;   animation: slide 1s alternate;   background: linear-gradient(top, #e3e3e3 10%, white);   display: box;}

Non-standard attribute writing to be automatically expanded

.container {-webkit-box-shadow: 20px;-moz-box-shadow: 20px;box-shadow: 20px;-webkit-transition: -webkit-box-shadow 2s;-moz-transition: -moz-box-shadow 2s;-o-transition: box-shadow 2s;-ms-transition: box-shadow 2s;transition: box-shadow 2s;-webkit-border-top-right-radius: 4px;-moz-border-radius-topright: 4px;border-top-right-radius: 4px;-webkit-border-bottom-left-radius: 4px;-moz-border-radius-bottom-left: 4px;border-bottom-left-radius: 4px;-webkit-animation: slide 1s alternate;-moz-animation: slide 1s alternate;-ms-animation: slide 1s alternate;animation: slide 1s alternate;background: -webkit-linear-gradient(top, #e3e3e3 10%, white);background: -moz-linear-gradient(top, #e3e3e3 10%, white);background: -o-linear-gradient(top, #e3e3e3 10%, white);background: -ms-linear-gradient(top, #e3e3e3 10%, white);background: linear-gradient(top, #e3e3e3 10%, white);display: -webkit-box;display: -moz-box;display: box;}

In this case, you need to check whether there are non-standard attributes and non-standard Attributes Based on the attribute values of the css file in sequence. Accordingly, You need to determine the key-value pairs or single values in the Rule array from the outside.

My main logic is as follows:
For example, it's time to check css.

border-top-right-radius : 4px;

In this line, the code check finds that the property name "border-top-right-radius" requires three compatibility Methods: webkit, moz, and o. The value of 4px is not compatible (note: here we also add a judgment on the value because there are some special attributes such as transition, and their attribute names and values must be compatible at the same time). A total of three times must be compatible.
Then, we loop through webkit, moz, and o and want to read three rules from the attribute name rules:

'webkit'=>'-webkit-border-top-right-radius','moz'=>'-moz-border-radius-topright','o'=>'-o-border-top-right-radius'

Of course, since the simplified scheme is used when writing rules, you need to judge webkit, moz, and o during reading, check whether it is a value or a key name in the array. If it is a key name, the value is obtained directly. If it is a value, the required string is generated according to the default rule. The problem lies here.
Loop in the Rule array, making internal judgments, and checking in css is unrealistic in this scenario (especially when css is huge ). All I can think of is to use the Continuous Combination of array_key_exists () and array_search () for verification. It also needs to filter out duplicate values in single-value and key-value pairs, Which is inefficient.

Of course, when I was actually doing this, I simply bypassed this problem and used the function to re-format the rule array for simplified writing, during formatting, you also encountered a class internal attribute name reference problem in the form of $ this-> $ propname, and then forcibly solved it with the & pointer, however, I encountered a huge number of questions. As a wild self-study party, it was under great pressure. I will try again in the next example ).

The actual project is bypassed, but as a problem encountered during code writing, I still want to ask experts for their opinions,
How to quickly determine the three situations of a string in the array from the External: nonexistent, key name, value ......

Reply content:

Thanks to @ joyqi for your attention. Put the actual Code directly as recommended.

This is my sample CSS3. Expand the php with non-standard attributes.

The existing input data is as follows:

 Array ('webkit', 'moz', 'ms'), 'border-radius '=> array ('webkit', 'moz', 'O '), 'border-top-right-radius '=> array ('webkit', 'moz' =>'-moz-border-radius-topright ', 'O '), 'border-top-left-radius '=> array ('webkit', 'moz' =>'-moz-border-radius-topleft', 'O '), 'border-bottom-right-radius '=> array ('webkit', 'moz' =>'-moz-border-radius-bottomright', 'O '), 'border-bottom-left-radius '=> array ('webkit', 'moz' =>'-moz-border-radius-bott Omleft ', 'O'), 'border-color' => array ('moz'), 'box-shadow' => array ('webkit ', 'moz ', 'o'), 'transfer' => array ('webkit', 'moz', 'ms', 'O'), 'transform' => array ('webkit ', 'moz', 'ms', 'O '),......); $ _ valuerules = array (// css3 compatible value table is appended to the header 'linear-gradient' => array ('webkit ', 'moz', 'ms', 'O'), 'box' => array ('webkit ', 'moz', 'O '), 'box-shadow' => array ('webkit ', 'moz') ......);?>

Process a css file according to the preceding rules.

.container {   box-shadow: 20px;   transition: box-shadow 2s;   border-top-right-radius: 4px;   border-bottom-left-radius: 4px;   animation: slide 1s alternate;   background: linear-gradient(top, #e3e3e3 10%, white);   display: box;}

Non-standard attribute writing to be automatically expanded

.container {-webkit-box-shadow: 20px;-moz-box-shadow: 20px;box-shadow: 20px;-webkit-transition: -webkit-box-shadow 2s;-moz-transition: -moz-box-shadow 2s;-o-transition: box-shadow 2s;-ms-transition: box-shadow 2s;transition: box-shadow 2s;-webkit-border-top-right-radius: 4px;-moz-border-radius-topright: 4px;border-top-right-radius: 4px;-webkit-border-bottom-left-radius: 4px;-moz-border-radius-bottom-left: 4px;border-bottom-left-radius: 4px;-webkit-animation: slide 1s alternate;-moz-animation: slide 1s alternate;-ms-animation: slide 1s alternate;animation: slide 1s alternate;background: -webkit-linear-gradient(top, #e3e3e3 10%, white);background: -moz-linear-gradient(top, #e3e3e3 10%, white);background: -o-linear-gradient(top, #e3e3e3 10%, white);background: -ms-linear-gradient(top, #e3e3e3 10%, white);background: linear-gradient(top, #e3e3e3 10%, white);display: -webkit-box;display: -moz-box;display: box;}

In this case, you need to check whether there are non-standard attributes and non-standard Attributes Based on the attribute values of the css file in sequence. Accordingly, You need to determine the key-value pairs or single values in the Rule array from the outside.

My main logic is as follows:
For example, it's time to check css.

border-top-right-radius : 4px;

In this line, the code check finds that the property name "border-top-right-radius" requires three compatibility Methods: webkit, moz, and o. The value of 4px is not compatible (note: here we also add a judgment on the value because there are some special attributes such as transition, and their attribute names and values must be compatible at the same time). A total of three times must be compatible.
Then, we loop through webkit, moz, and o and want to read three rules from the attribute name rules:

'webkit'=>'-webkit-border-top-right-radius','moz'=>'-moz-border-radius-topright','o'=>'-o-border-top-right-radius'

Of course, since the simplified scheme is used when writing rules, you need to judge webkit, moz, and o during reading, check whether it is a value or a key name in the array. If it is a key name, the value is obtained directly. If it is a value, the required string is generated according to the default rule. The problem lies here.
Loop in the Rule array, making internal judgments, and checking in css is unrealistic in this scenario (especially when css is huge ). All I can think of is to use the Continuous Combination of array_key_exists () and array_search () for verification. It also needs to filter out duplicate values in single-value and key-value pairs, Which is inefficient.

Of course, when I was actually doing this, I simply bypassed this problem and used the function to re-format the rule array for simplified writing, during formatting, you also encountered a class internal attribute name reference problem in the form of $ this-> $ propname, and then forcibly solved it with the & pointer, however, I encountered a huge number of questions. As a wild self-study party, it was under great pressure. I will try again in the next example ).

The actual project is bypassed, but as a problem encountered during code writing, I still want to ask experts for their opinions,
How to quickly determine the three situations of a string in the array from the External: nonexistent, key name, value ......

In fact, the single value you mentioned also has a key, but php can save the key name stored in order.

Foreach ($ a as $ key => $ val) {if (is_int ($ key) {// processing single value} else {// processing key value }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.