diff options
author | Pascal Kriete <pascal.kriete@ellislab.com> | 2010-11-04 22:59:52 +0100 |
---|---|---|
committer | Pascal Kriete <pascal.kriete@ellislab.com> | 2010-11-04 22:59:52 +0100 |
commit | e917f9be8b05c81357c1c2c9730d5060685d644d (patch) | |
tree | b6a7d5ce8ba57b69ba61454f77829b04f2ce5974 /user_guide/helpers/array_helper.html | |
parent | 5b2d2da5ae2e97043c6bef53e565d30e50196e2b (diff) | |
parent | e1f6e9ddff788f6a154f5f35dc117d14aeb0c484 (diff) |
Automated merge with http://hg.ellislab.com/CodeIgniter2
Diffstat (limited to 'user_guide/helpers/array_helper.html')
-rw-r--r-- | user_guide/helpers/array_helper.html | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/user_guide/helpers/array_helper.html b/user_guide/helpers/array_helper.html index c0bdd78e3..6d95c4a5f 100644 --- a/user_guide/helpers/array_helper.html +++ b/user_guide/helpers/array_helper.html @@ -100,7 +100,58 @@ echo element('size', $array, NULL); echo random_element($quotes);</code> +<h2>elements()</h2> +<p>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 FALSE, or whatever you've specified as the default value via the third parameter. Example:</p> + +<code> +$array = array(<br /> + 'color' => 'red',<br /> + 'shape' => 'round',<br /> + 'radius' => '10',<br /> + 'diameter' => '20'<br /> +);<br /> +<br /> +$my_shape = elements(array('color', 'shape', 'height'), $array);<br /> +</code> + +<p>The above will return the following array:</p> + +<code> +array(<br /> + 'color' => 'red',<br /> + 'shape' => 'round',<br /> + 'height' => FALSE<br /> +); +</code> + +<p>You can set the third parameter to any default value you like:</p> + +<code> +$my_shape = elements(array('color', 'shape', 'height'), $array, NULL);<br /> +</code> + +<p>The above will return the following array:</p> + +<code> +array(<br /> + 'color' => 'red',<br /> + 'shape' => 'round',<br /> + 'height' => NULL<br /> +); +</code> + +<p>This is useful when sending the <kbd>$_POST</kbd> array to one of your Models. This prevents users from +sending additional POST data to be entered into your tables:</p> + +<code> +$this->load->model('post_model');<br /> +<br /> +$this->post_model->update(elements(array('id', 'title', 'content'), $_POST)); +</code> + +<p>This ensures that only the id, title and content fields are sent to be updated.</p> </div> <!-- END CONTENT --> |