Skip to content

Commit 36b8746

Browse files
committed
Translate array helper
1 parent 0c8b4b0 commit 36b8746

File tree

1 file changed

+36
-41
lines changed

1 file changed

+36
-41
lines changed

source/helpers/array_helper.rst

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
############
2-
Array Helper
2+
Array 輔助函數
33
############
44

5-
The Array Helper file contains functions that assist in working with
6-
arrays.
5+
Array 輔助函數包含了各種輔助陣列操作的相關函數。
76

87
.. contents::
98
:local:
@@ -12,34 +11,32 @@ arrays.
1211

1312
<div class="custom-index container"></div>
1413

15-
Loading this Helper
14+
導入輔助函數
1615
===================
1716

18-
This helper is loaded using the following code::
17+
Array 輔助函數的載入語法如下:
1918

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

2221

23-
Available Functions
22+
可用函數格式
2423
===================
2524

26-
The following functions are available:
25+
允許使用的函數格式如下:
2726

2827

2928
.. php:function:: element($item, $array[, $default = NULL])
3029
31-
:param string $item: Item to fetch from the array
32-
:param array $array: Input array
33-
:param bool $default: What to return if the array isn't valid
34-
:returns: NULL on failure or the array item.
35-
:rtype: mixed
30+
:param string $item: 欲從來源陣列中取出的元素
31+
:param array $array: 來源陣列
32+
:param bool $default: 如果非有效來源陣列要回傳的值
33+
:returns: 失敗時回傳 NULL 成功時回傳陣列元素
34+
:rtype: 各種型態皆有
3635

37-
Lets you fetch an item from an array. The function tests whether the
38-
array index is set and whether it has a value. If a value exists it is
39-
returned. If a value does not exist it returns NULL, or whatever you've
40-
specified as the default value via the third parameter.
36+
此輔助函數可讓你從來源陣列中提取元素,也可測試出陣列中是否具有索引和值,如果存在將會回傳該值,反之則回傳 NULL 或任何你標明在第三個參數當中的預設值。
4137

42-
Example::
38+
範例
39+
::
4340

4441
$array = array(
4542
'color' => 'red',
@@ -53,18 +50,16 @@ The following functions are available:
5350

5451
.. php:function:: elements($items, $array[, $default = NULL])
5552
56-
:param string $item: Item to fetch from the array
57-
:param array $array: Input array
58-
:param bool $default: What to return if the array isn't valid
59-
:returns: NULL on failure or the array item.
60-
:rtype: mixed
53+
:param string $item: 欲從來源陣列中取出的元素組
54+
:param array $array: 來源陣列
55+
:param bool $default: 如果非有效來源陣列要賦予的值
56+
:returns: 失敗時回傳 NULL 成功時回傳陣列元素組
57+
:rtype: 各種型態皆有
6158

62-
Lets you fetch a number of items from an array. The function tests
63-
whether each of the array indices is set. If an index does not exist it
64-
is set to NULL, or whatever you've specified as the default value via
65-
the third parameter.
59+
此輔助函數可讓你從來源陣列中提取元素組,也可測試出其在陣列是否有被定義,如果元素未定義會把值設定為 NULL 或者你在第三個參數中所定義的任何值。
6660

67-
Example::
61+
範例
62+
::
6863

6964
$array = array(
7065
'color' => 'red',
@@ -75,30 +70,30 @@ The following functions are available:
7570

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

78-
The above will return the following array::
73+
上方程式碼執行後將會回傳此陣列:
74+
::
7975

8076
array(
8177
'color' => 'red',
8278
'shape' => 'round',
8379
'height' => NULL
8480
);
8581

86-
You can set the third parameter to any default value you like.
82+
第三個參數的預設賦予值可以依你喜好方式設置。
8783
::
8884

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

91-
The above will return the following array::
87+
上方程式碼執行後將會回傳此陣列:
88+
::
9289

9390
array(     
9491
'color' => 'red',
9592
'shape' => 'round',
9693
'height' => 'foobar'
9794
);
9895

99-
This is useful when sending the ``$_POST`` array to one of your Models.
100-
This prevents users from sending additional POST data to be entered into
101-
your tables.
96+
此函數在傳送 ``$_POST`` 陣列至 Model 時相當有用,可以避免使用者混入額外的 POST data 進你的資料表。
10297

10398
::
10499

@@ -107,19 +102,19 @@ The following functions are available:
107102
elements(array('id', 'title', 'content'), $_POST)
108103
);
109104

110-
This ensures that only the id, title and content fields are sent to be
111-
updated.
105+
可以保證只有 id、title、content 這三個欄位會被送出更新。
112106

113107

114108
.. php:function:: random_element($array)
115109
116-
:param array $array: Input array
117-
:returns: A random element from the array
118-
:rtype: mixed
110+
:param array $array: 來源陣列
111+
:returns: 來源陣列中的隨機元素
112+
:rtype: 各種型態皆有
119113

120-
Takes an array as input and returns a random element from it.
114+
在來源陣列中隨機挑選一個元素回傳。
121115

122-
Usage example::
116+
範例
117+
::
123118

124119
$quotes = array(
125120
"I find that the harder I work, the more luck I seem to have. - Thomas Jefferson",
@@ -130,4 +125,4 @@ The following functions are available:
130125
"Chance favors the prepared mind - Louis Pasteur"
131126
);
132127

133-
echo random_element($quotes);
128+
echo random_element($quotes);

0 commit comments

Comments
 (0)