|
Declare an array
|
int[] x = new int[5];
|
// key only integer or string
// value any
$array = array(1, 2, 3, 4, 5);
$arr = array("foo" => "bar", 12 => true);
|
// key only integer or string
// value any
$array = array(1, 2, 3, 4, 5);
$arr = array("foo" => "bar", 12 => true);
|
var arr:Array = [1,2,3];
|
new Array()
new Array(len)
new Array([item0,[item1,[item2,...]]]
//Example
var objArray=new Array();
var arr=[0,1,2,3,4,5,6];
|
a = [ 1, 'cat', 3.14 ]
|
|
Initialize an array
|
int[] x = new int[5] {
1, 2, 3, 4, 5};
|
$arr = array(
"somearray" => array(
6 => 5,
13 => 9,
"a" => 42));
|
$arr = array(
"somearray" => array(
6 => 5,
13 => 9,
"a" => 42));
|
var arr:Array = new Array(1,2,3);
|
var arr=[0,1,2,3,4,5,6];
var complexArray = [[1,{x:1, y:2}], [2, {x:3, y:4}]];
|
inst_section = {
'cello' => 'string',
'trumpet' => 'brass',
'violin' => 'string'
}
|
|
Add or remove element
|
|
$arr["x"] = 42;
// This adds a new element to
// the array with key "x"
$array[] = 6;
unset($arr[5]);
// This removes the element from the array
|
$arr["x"] = 42;
// This adds a new element to
// the array with key "x"
unset($arr[5]);
// This removes the element from the array
|
arr.push(item); arr.splice(at,count);
|
// Add elements
objArray.push([value1[,value2[,....]]]);
//[1,2,3, 4].push("a","b") result is [1,2,3,4,"a","b"]
objArray.pop(); //remove the last element[1,2,3, 4].pop() result is [1,2,3]
objArray.shift(); //remove the first element.
objArray.splice(start, deleteCount, [item1[, item2[, . . . [,itemN]]]])
|
|
|
Reallocate array
|
n/a
|
// This deletes the whole array
unset($arr);
|
// This deletes the whole array
unset($arr);
|
n/a
|
n/a
|
|