summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/helpers/array_helper.rst
diff options
context:
space:
mode:
Diffstat (limited to 'user_guide_src/source/helpers/array_helper.rst')
-rw-r--r--user_guide_src/source/helpers/array_helper.rst66
1 files changed, 27 insertions, 39 deletions
diff --git a/user_guide_src/source/helpers/array_helper.rst b/user_guide_src/source/helpers/array_helper.rst
index 15b5e17c4..9435b3ac7 100644
--- a/user_guide_src/source/helpers/array_helper.rst
+++ b/user_guide_src/source/helpers/array_helper.rst
@@ -10,9 +10,7 @@ arrays.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('array');
@@ -21,20 +19,19 @@ The following functions are available:
element()
=========
-.. php:method:: element($item, $array, $default = NULL)
-
- :param string $item: Item to fetch from the array
- :param array $array: Input array
- :param boolean $default: What to return if the array isn't valid
- :returns: NULL on failure or the array item.
+.. php:function:: element($item, $array, $default = NULL)
+ :param string $item: Item to fetch from the array
+ :param array $array: Input array
+ :param bool $default: What to return if the array isn't valid
+ :returns: NULL on failure or the array item.
Lets you fetch an item from an array. The function tests whether the
array index is set and whether it has a value. If a value exists it is
returned. If a value does not exist it returns NULL, or whatever you've
-specified as the default value via the third parameter. Example
+specified as the default value via the third parameter.
-::
+Example::
$array = array(
'color' => 'red',
@@ -48,21 +45,19 @@ specified as the default value via the third parameter. Example
elements()
==========
+.. php:function:: elements($items, $array, $default = NULL)
+
+ :param string $item: Item to fetch from the array
+ :param array $array: Input array
+ :param bool $default: What to return if the array isn't valid
+ :returns: NULL on failure or the array item.
+
Lets you fetch a number of items from an array. The function tests
whether each of the array indices is set. If an index does not exist it
is set to NULL, or whatever you've specified as the default value via
the third parameter.
-.. php:method:: elements($items, $array, $default = NULL)
-
- :param string $item: Item to fetch from the array
- :param array $array: Input array
- :param boolean $default: What to return if the array isn't valid
- :returns: NULL on failure or the array item.
-
-Example
-
-::
+Example::
$array = array(
'color' => 'red',
@@ -73,9 +68,7 @@ Example
$my_shape = elements(array('color', 'shape', 'height'), $array);
-The above will return the following array
-
-::
+The above will return the following array::
array(
'color' => 'red',
@@ -83,15 +76,12 @@ The above will return the following array
'height' => NULL
);
-You can set the third parameter to any default value you like
-
+You can set the third parameter to any default value you like.
::
$my_shape = elements(array('color', 'shape', 'height'), $array, 'foobar');
-The above will return the following array
-
-::
+The above will return the following array::
array(     
'color' => 'red',
@@ -99,9 +89,9 @@ The above will return the following array
'height' => 'foobar'
);
-This is useful when sending the $_POST array to one of your Models.
+This is useful when sending the ``$_POST`` array to one of your Models.
This prevents users from sending additional POST data to be entered into
-your tables
+your tables.
::
@@ -116,15 +106,14 @@ updated.
random_element()
================
-Takes an array as input and returns a random element from it. Usage
-example
+.. php:function:: random_element($array)
-.. php:method:: random_element($array)
+ :param array $array: Input array
+ :returns: string (a random element from the array)
- :param array $array: Input array
- :returns: String - Random element from the array.
+Takes an array as input and returns a random element from it.
-::
+Usage example::
$quotes = array(
"I find that the harder I work, the more luck I seem to have. - Thomas Jefferson",
@@ -135,5 +124,4 @@ example
"Chance favors the prepared mind - Louis Pasteur"
);
- echo random_element($quotes);
-
+ echo random_element($quotes); \ No newline at end of file