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, font size 12 */$ B = 'Rabbit, cat meat, mutton, beef ,'; /* the color of this character segment is purple. the font size is 16 */$ c = 'Hello, thank you, goodbye, very good,';/* the color of this character segment is yellow, font size: 20 * // PHP string after multiple arrays are traversed and CSS format is added before random 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 ";}