예배 규칙서 찾다
Array Array Helper Benchmarking Benchmarking Class Caching Caching Driver Calendaring Calendaring Class CAPTCHA CAPTCHA Helper Config Config Class Cookie Cookie Helper Database Connecting to your Database Custom Function Calls Database Caching Class Database Configuration Database Forge Class Database Metadata Database Quick Start: Example Code Database Reference Database Utility Class DB Driver Reference Generating Query Results Queries Query Builder Class Query Helper Methods Transactions Date Date Helper Directory Directory Helper Download Download Helper Email Email Class Email Helper Encrypt Encrypt Class Encryption Encryption Library File File Helper File Uploading File Uploading Class Form Form Helper Form Validation Form Validation FTP FTP Class Functions compatibility_functions common_functions HTML HTML Helper HTML Table HTML Table Class Image Manipulation Image Manipulation Class Inflector Inflector Helper Input Input Class Javascript Javascript Class Language Language Class Language Helper Loader Loader Class Migrations Migrations Class Number Number Helper Output Output Class Pagination Pagination Class Path Path Helper Security Security Class Security Helper Session Session Library Shopping Cart Shopping Cart Class Smiley Smiley Helper String String Helper Template Parser Template Parser Class Text Text Helper Trackback Trackback Class Typography Typography Class Typography Helper Unit Testing Unit Testing Class URI URL User Agent XML XML-RPC and XML-RPC Server Zip Encoding Zip Encoding Class XML-RPC and XML-RPC Server Classes XML Helper User Agent Class URL Helper URI Class
문자

Array Helper文件包含有助于处理数组的函数。

  • 加载此助手

  • 可用职能

加载此助手

使用以下代码加载此助手:

$this->load->helper('array');

可用职能

现有下列职能:

element($item, $array[, $default = NULL])

参数:

$ item(string) - 从数组中获取的项目$ array(array) - 输入数组$ default(bool) - 如果数组无效

返回:

NULL失败或数组项。

返回类型:

  • $item (string) -从数组中获取的项

  • $array (array) -输入数组

  • $ defaultbool) - 如果数组无效应该返回什么。

返回:失败或数组项时返回NULL。
返回类型:混合
让您从数组中获取项目。该函数测试数组索引是否已设置以及是否有值。如果存在值,则返回该值。如果值不存在,则返回NULL,或者通过第三个参数指定为默认值。

例子:

$ array = array('color'=>'red','shape'=>'round','size'=>'');

 echo元素('color',$ array); //返回“红色”

echo元素('size',$ array,'foobar'); //返回“foobar”

elements($items, $array[, $default = NULL])

参数:

$ item(string) - 从数组中获取的项目$ array(array) - 输入数组$ default(bool) - 如果数组无效

返回:

NULL失败或数组项。

返回类型:

  • $ itemstring) - 从数组中获取的项目

  • $ arrayarray) - 输入数组

  • $ defaultbool) - 如果数组无效那么返回什么

返回:失败或数组项时返回NULL。
返回类型:混合
让您从数组中获取多个项目。该函数测试是否设置每个数组索引。如果索引不存在,它将被设置为NULL,或者通过第三个参数指定为默认值。

例子:

$ array = array('color'=>'red','shape'=>'round','radius'=>'10','diameter'=>'20'); 
$ my_shape = elements(array('color','shape','height'),$ array);

以上将返回以下数组:

array('color'=>'red','shape'=>'round','height'=> NULL);

您可以将第三个参数设置为您喜欢的任何默认值。

$ my_shape = elements(array('color','shape','height'),$ array,'foobar');

以上将返回以下数组:

数组('color'=>'red','shape'=>'round','height'=>'foobar');

$_POST数组发送到其中一个模型时非常有用。这可以防止用户发送额外的POST数据输入到表中。

$this - >负载>模型( 'post_model'); $ this-> post_model-> update(elements(array('id','title','content'),$ _POST));

这确保只有id,标题和内容字段被发送来更新。

random_element($array)

参数:

$ array(array) - 输入数组

返回:

数组中的随机元素

返回类型:

  • $ arrayarray) - 输入数组

返回:数组中的一个随机元素
返回类型:混合
将数组作为输入并从中返回一个随机元素。

用法示例:

$quotes = array(         "I find that the harder I work, the more luck I seem to have. - Thomas Jefferson",         
"Don't stay in bed, unless you can make money in bed. - George Burns",         
"We didn't lose the game; we just ran out of time. - Vince Lombardi",         
"If everything seems under control, you're not going fast enough. - Mario Andretti",         
"Reality is merely an illusion, albeit a very persistent one. - Albert Einstein",         
"Chance favors the prepared mind - Louis Pasteur" );  
echo random_element($quotes);
이전 기사: 다음 기사: