PHP random output after adding CSS format to the string after multiple arrays are traversed. How can this problem be solved?

Source: Internet
Author: User
PHP random output after adding CSS format to the string after multiple arrays are traversed. $ A giraffe, elephant, kitten, Tiger,; * the color of this section is red, the font size is 12 * $ B rabbit, cat meat, mutton, beef, * the color of this section is purple, font size 16 * $ c Hello, thank you, goodbye, very good,; * the color of this segment is yellow, and the font size is 20 ** three-segment string, separated by commas. It is used to split the data into arrays * $ aaexplode (& q PHP multiple arrays after traversing the strings plus the CSS format and then randomly output.
$ A = 'Giraffe, elephant, kitten, Tiger, ';/* the color of this section is red, and the font size is 12 */

$ B = 'Rabbit, cat meat, mutton, beef, ';/* the character color is purple and the font size is 16 */

$ C = 'Hello, thank you. Goodbye, good. ';/* the color of this section is yellow and the font size is 20 */

/* Three-segment string separated by commas. Split to an array using the next step */

$ Aa = explode (",", $ a. $ B. $ c );
/* After the array, I want to use the array_rand () function and traverse the randomly arranged strings */

The question now is how to set the CSS color and text size for the three strings $ a $ B $ c. Then, the data is aggregated and output is arranged randomly.


------ Solution --------------------
Try again to see the effect
Header ('content-type: text/html; charset = utf-8 ');

$ Arr = array ('giraffe ', 'Elephant', 'kitten ', 'Tiger', 'rabbit ', 'Cat meat', 'mutton ', 'Beef ', 'Hello ', 'Thank you', 'Goodbye ', 'good job ');
$ Style_arr = array ();

Foreach ($ arr as $ val)
{
$ Font_size = rand (12, 20). 'px ';
$ Font_color = 'rgb '.' ('. rand (0,255).', '. rand (0,255).', '. rand (0,255 ).')';
$ Style = '';
$ Font = '';
$ Style_arr [] = $ style. $ val. $ font;
}
Shuffle ($ style_arr );
Foreach ($ style_arr as $ val2)
{
Echo $ val2 .'';
}
------ Solution --------------------
PHP code
$ A = 'Giraffe, elephant, kitten, Tiger '; $ B = 'Rabbit, cat meat, mutton, beef'; $ c = 'Hello, thank you, goodbye, good-nature '; echo <STYLESTYLE; $ aa = explode (',', $ a); array_walk ($ aa, 'func', 'C1'); $ bb = explode (',', $ B); array_walk ($ bb, 'func', 'C2 '); $ cc = explode (', ', $ c); array_walk ($ cc, 'func ', 'C3'); $ ar = array_merge ($ aa, $ bb, $ cc); shuffle ($ ar); echo join ('', $ ar ); function func (& $ item, $ key, $ param) {$ item = "$ item ";}

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.