[wordpress插件] array_partitionarray_partition

wordpress 插件 文章 2020-02-21 06:40 642 0 全屏看文

AI助手支持GPT4.0

评分
0
描述

This plugin provides the PHP function c2c_array_partition() to split an array into any number of sub-arrays, suitable for creating evenly distributed, vertically filled “columns”.

此插件提供PHP函数 c2c_array_partition(),可将数组拆分为任意数量的子数组,适用于创建均匀分布的垂直填充的“列”。

Also known as “chunking” or “partitioning”.

也称为“分块”或“分区”。

For example:

例如:

$topics = array( "aardvark", "bear", "cat", "dog", "emu", "fox", "gnu", "hippo", "ibis", "jackal"

  $ topics = array(“ aardvark”,“ bear”,“ cat”,“ dog”,“ emu”,“ fox”,“ gnu”,“ hippo”,“ ibis”,“ jackal” 

);

);

print_r( c2c_array_partition( $topics, 4 ) );

print_r(c2c_array_partition($ topics,4));

Yields:

收益:

Array

 数组

(    

(    

[0] => Array        

[0] =>数组        

(            

(            

[0] => ant            

[0] =>蚂蚁            

[1] => bear            

[1] =>熊            

[2] => cat        

[2] =>猫        

)    

)    

[1] => Array        

[1] =>数组        

(            

(            

[0] => dog            

[0] =>狗            

[1] => emu            

[1] => mu            

[2] => fox        

[2] =>狐狸        

)    

)    

[2] => Array        

[2] =>数组        

(            

(            

[0] => gnu            

[0] => gnu            

[1] => hippo        

[1] =>河马        

)    

)    

[3] => Array        

[3] =>数组        

(            

(            

[0] => ibis            

[0] =>宜必思            

[1] => jackal        

[1] =>狐狼        

)

)

Note the array elements are distributed into the requested 4 “columns” as evenly as possible.

请注意,数组元素应尽可能均匀地分配到所请求的4个“列”中。

The function will fill as many partitions as requested, as long as there are enough elements in the array to do so.

只要数组中有足够的元素,该函数将填充请求的分区。

Any remaining unfilled partitions will be represented as empty arrays.

任何剩余的未填充分区都将表示为空数组。

In contrast, using PHP’s built-in array_chunk() as such:

相反,使用PHP的内置 array_chunk()这样:

print_r( array_chunk( $topics, 4 ) );

  print_r(array_chunk($ topics,4));

Yields:

收益:

Array

 数组

(    

(    

[0] => Array        

[0] =>数组        

(            

(            

[0] => aardvark            

[0] =>土豚            

[1] => bear            

[1] =>熊            

[2] => cat            

[2] =>猫            

[3] => dog        

[3] =>狗        

)    

)    

[1] => Array        

[1] =>数组        

(            

(            

[0] => emu            

[0] => mu            

[1] => fox            

[1] =>狐狸            

[2] => gnu            

[2] => gnu            

[3] => hippo        

[3] =>河马        

)    

)    

[2] => Array        

[2] =>数组        

(            

(            

[0] => ibis            

[0] =>宜必思            

[1] => jackal        

[1] =>狐狼        

)

)

It can be sent an array of any data types or objects.

可以向其发送任何数据类型或对象的数组。

Links: Plugin Homepage |

链接:插件主页 |

Plugin Directory Page |

插件目录页面 |

GitHub |

GitHub |

Author Homepage

作者主页

Examples

示例

  <?php  

$topics = array( "ant", "bear", "cat" );  

$ topics = array(“ ant”,“ bear”,“ cat”);  

print_r( c2c_array_partition( $topics, 5 ) );

print_r(c2c_array_partition($ topics,5));

?>

?>

=>

=>

Array

 数组

(    

(    

[0] => Array        

[0] =>数组        

(            

(            

[0] => ant        

[0] =>蚂蚁        

)    

)    

[1] => Array        

[1] =>数组        

(            

(            

[0] => bear        

[0] =>熊        

)    

)    

[2] => Array        

[2] =>数组        

(            

(            

[0] => cat        

[0] =>猫        

)    

)    

[3] => Array        

[3] =>数组        

(        

(        

)    

)    

[4] => Array        

[4] =>数组        

(        

(        

)

)

Also see Description section for another example.

另请参见说明部分。

Definitely check out the packaged unit test file as it contains various examples.

绝对要检查打包的单元测试文件,因为它包含各种示例。

安装步骤

    1. Install via the built-in WordPress plugin installer.

    2. 通过内置的WordPress插件安装程序进行安装。

      Or download and unzip array-partition.zip inside the plugins directory for your site (typically wp-content/plugins/)

    3. 或在您网站的插件目录中下载 array-partition.zip 并解压缩(通常为 wp-content / plugins /

    4. Activate the plugin through the ‘Plugins’ admin menu in WordPress
    5. 通过WordPress中的“插件”管理菜单激活插件

    6. Use the c2c_array_partition() function in your template(s) or code as desired.
    7. 根据需要在模板中使用 c2c_array_partition()函数或根据需要编写代码。

下载地址
https://downloads.wordpress.org/plugin/array-partition.1.2.8.zip
-EOF-

AI助手支持GPT4.0