This shows you the differences between two versions of the page.
uphp:functions:array [2017/04/06 11:40] jeff |
uphp:functions:array [2021/09/13 05:57] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======array====== | ||
- | |||
- | < | ||
- | |||
- | Create an < | ||
- | |||
- | ====Description==== | ||
- | |||
- | <well size=" | ||
- | < | ||
- | <span style=" | ||
- | <span style=" | ||
- | </ | ||
- | [[array]] ( | ||
- | < | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | </ | ||
- | </ | ||
- | |||
- | ====Parameters==== | ||
- | |||
- | < | ||
- | |||
- | ====Return Value==== | ||
- | |||
- | < | ||
- | |||
- | ====Examples==== | ||
- | |||
- | **Creating Arrays:** | ||
- | |||
- | <code php> | ||
- | <? | ||
- | $arr=array(); | ||
- | $arr[0]=' | ||
- | $arr[]=' | ||
- | $arr[2]=' | ||
- | |||
- | $arr2=array(1, | ||
- | | ||
- | $arr3=array(" | ||
- | ?> | ||
- | </ | ||
- | |||
- | **Key/Value Pairs:** | ||
- | |||
- | <code php> | ||
- | < | ||
- | $arr=array(); | ||
- | $arr[' | ||
- | $arr[' | ||
- | |||
- | // iterate through the array and print out all keys and their associated values | ||
- | for ($i=0; $i < sizeof($arr); | ||
- | $key=array_key($arr, | ||
- | print(" | ||
- | } | ||
- | ?></ | ||
- | </ | ||
- | |||
- | The above example will output: | ||
- | < | ||
- | Key at Index 0 is name and value is John | ||
- | Key at Index 1 is age and value is 33 | ||
- | </ | ||
- | |||
- | ====Note==== | ||
- | |||
- | An [[indexed array]] is a more efficient way to store variables in memory if the size and data type is known beforehand. The [[array()]] function creates a hashed < | ||
- | |||
- | ====See Also==== | ||
- | |||
- | [[indexed_array()]] - Create an < | ||
- | |||
- | [[sizeof()]] - Return the number of elements in an < | ||
- | |||
- | [[print_r()]] - Dump the contents of an < | ||
- | |||
- | [[array_key()]] - Return the key for an < | ||
- | |||
- | [[array_keys()]] - Return keys for an < | ||
- | |||
- | [[uphp: | ||