Home Backend Development PHP Tutorial PHP多个数组遍历后的字符串加CSS格式后再随机输出。该怎么解决

PHP多个数组遍历后的字符串加CSS格式后再随机输出。该怎么解决

Jun 13, 2016 am 10:11 AM
array background font size style

PHP多个数组遍历后的字符串加CSS格式后再随机输出。
$a='长颈鹿,大象,小猫,老虎,';/*此段字符颜色红色,字号12*/

$b='兔子,猫肉,羊肉,牛肉,';/*此段字符颜色紫色,字号16*/

$c='你好,谢谢,再见,很好,';/*此段字符颜色黄色,字号20*/

/*三段字符串,分别与中间逗号分割。用以下一步的分割成数组*/

$aa=explode(",",$a.$b.$c);
/*数组后,然后我想的是用array_rand()函数,然后遍历出随机排列的字符串*/

现在的问题是,如何将$a $b $c,这三组字符串分别设定好CSS颜色,文字大小。然后汇总在一起,再随机排列输出。


------解决方案--------------------
再试试这个,看看效果
header('content-type:text/html; charset=utf-8');

$arr = array('长颈鹿', '大象', '小猫', '老虎', '兔子', '猫肉', '羊肉', '牛肉', '你好', '谢谢', '再见', '很好');
$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.' ';
}
------解决方案--------------------

PHP code
$a = '长颈鹿,大象,小猫,老虎';$b = '兔子,猫肉,羊肉,牛肉';$c = '你好,谢谢,再见,很好';echo .c1 { background:red; font-size:12px; }.c2 { background:green; font-size:16px; }.c3 { background:orange; font-size:20px; }STYLE;$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 = "<span class="$param">$item</span>";}<div class="clear">
                 
              
              
        
            </div>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Use java's File.length() function to get the size of the file Use java's File.length() function to get the size of the file Jul 24, 2023 am 08:36 AM

Use Java's File.length() function to get the size of a file. File size is a very common requirement when dealing with file operations. Java provides a very convenient way to get the size of a file, that is, using the length() method of the File class. . This article will introduce how to use this method to get the size of a file and give corresponding code examples. First, we need to create a File object to represent the file we want to get the size of. Here is how to create a File object: Filef

How to use CSS to achieve the rotating background animation effect of elements How to use CSS to achieve the rotating background animation effect of elements Nov 21, 2023 am 09:05 AM

How to use CSS to implement rotating background image animation effects of elements. Background image animation effects can increase the visual appeal and user experience of web pages. This article will introduce how to use CSS to achieve the rotating background animation effect of elements, and provide specific code examples. First, we need to prepare a background image, which can be any picture you like, such as a picture of the sun or an electric fan. Save the image and name it "bg.png". Next, create an HTML file and add a div element in the file, setting it to

How to modify element.style How to modify element.style Nov 24, 2023 am 11:15 AM

Methods for element.style to modify elements: 1. Modify the background color of the element; 2. Modify the font size of the element; 3. Modify the border style of the element; 4. Modify the font style of the element; 5. Modify the horizontal alignment of the element. Detailed introduction: 1. Modify the background color of the element, the syntax is "document.getElementById("myElement").style.backgroundColor = "red";"; 2. Modify the font size of the element, etc.

How to dynamically modify style in react How to dynamically modify style in react Dec 28, 2022 am 10:44 AM

Methods for react to dynamically modify style: 1. Add ref to the element whose style needs to be modified, with syntax such as "<div className='scroll-title clear-fix' ref={ this.manage }>"; 2. Through dynamic control The change of state modifies the style of the element; 3. By using JS code in the DOM, the display and hiding transitions of different DOMs are realized.

What are the new features in Vue3 style and how to use them What are the new features in Vue3 style and how to use them May 14, 2023 pm 10:52 PM

New features of style Vue3.2 version has made many upgrades to the style of single-file components, such as local styles, css variables, and styles exposed to templates. (Learning video sharing: Vue video tutorial) 1. Local style When the label has scoped attribute, its CSS will only be applied to the elements of the current component: hi.example{color:red;} 2. The depth selector is scoped If the selector in the style wants to make a more "deep" selection, that is, affect sub-components, you can use the :deep() pseudo-class: .a:deep(.b){/*...*/ }DOM content created through v-html will not be

Python's Pygame Font module - how to use text and fonts? Python's Pygame Font module - how to use text and fonts? Apr 23, 2023 pm 11:19 PM

Pygame's Font text and font Pygame uses the pygame.font module to create a font object to achieve the purpose of drawing text. Commonly used methods of this module are as follows: Name Description pygame.font.init() Initialize the font module pygame.font.quit() Uninitialize the font module pygame.font.get_init() Check whether the font module has been initialized and return a Boolean value . pygame.font.get_default_font() gets the file name of the default font. Returns the file name of the font in the system pygame.font.get_fonts() gets all

Sort array using Array.Sort function in C# Sort array using Array.Sort function in C# Nov 18, 2023 am 10:37 AM

Title: Example of using the Array.Sort function to sort an array in C# Text: In C#, array is a commonly used data structure, and it is often necessary to sort the array. C# provides the Array class, which has the Sort method to conveniently sort arrays. This article will demonstrate how to use the Array.Sort function in C# to sort an array and provide specific code examples. First, we need to understand the basic usage of the Array.Sort function. Array.So

Vue error: Unable to use v-bind to bind class and style correctly, how to solve it? Vue error: Unable to use v-bind to bind class and style correctly, how to solve it? Aug 26, 2023 pm 10:58 PM

Vue error: Unable to use v-bind to bind class and style correctly, how to solve it? In Vue development, we often use the v-bind instruction to dynamically bind class and style, but sometimes we may encounter some problems, such as being unable to correctly use v-bind to bind class and style. In this article, I will explain the cause of this problem and provide you with a solution. First, let’s understand the v-bind directive. v-bind is used to bind V

See all articles