非常教程

Codeigniter 3参考手册

数列 | Array

数组帮助 | Array Helper

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);

数列 | Array相关

Codeigniter 3

CodeIgniter 是一个PHP MVC框架,特点是超轻量级、有数据加密、有灵活URI路由等。对于 PHP 程序员来说,它小巧但功能强大。

主页 https://codeigniter.com/
源码 https://github.com/bcit-ci/CodeIgniter
版本 3
发布版本 3.1.5