Skip to content

Instantly share code, notes, and snippets.

@didlix
Created March 23, 2012 11:20
Show Gist options
  • Save didlix/2169718 to your computer and use it in GitHub Desktop.
Save didlix/2169718 to your computer and use it in GitHub Desktop.
Having fun with arrays in php 5.4
<?php
$slide_one = array(1,2,3);
$slide_two = array(
'cat' => array('cute', 'hairy'),
'dog' => array('noisy', 'bark bark')
);
$slide_three = [1,2,3];
$slide_four = [1,2,array(1,2,3)];
$slide_five = [1,2,[1,2,3]];
$slide_six = new ArrayObject(array(1,2,3));
$slide_seven = new ArrayObject([1,2,3]);
$slide_eight = [1,2,3,[1,2,[1,2,[1,2,3]]]];
$slide_nine = array(1,2,3,array(1,2,array(1,2,array(1,2,3))));
$slide_ten = array(1,2,3,array(1,2,array(1,2,new ArrayObject(array(1,'cat',3)))));
// Nice way to format these?
$slide_eleven = [1,2,3,
[1,3,
[1,2,3]
]
];
$slide_eleven =
[1,2,3, [1,3,
[1,2,3]
]
];
$slide_eleven =
[1,2,3,
[1,3,
[1,2,
[1,2,
[1,2,3]
]
]
]
];
// keyed arrays
$slide_twelve =
[
'access' => 'my_function',
'title' => ['label' => 'fred', 'type' => 'text', 'access' => null],
'named_groupset' => [
'field_one' => ['label' => 'fred', 'type' => 'text', 'access' => null],
'field_two' => ['label' => 'fred', 'type' => 'text', 'access' => null],
'field_three' => ['label' => 'fred', 'type' => 'text', 'access' => null],
]
];
var_dump($slide_one);
var_dump($slide_two);
var_dump($slide_three);
var_dump($slide_four);
var_dump($slide_five);
var_dump($slide_six);
var_dump($slide_seven);
var_dump($slide_eight);
var_dump($slide_nine);
var_dump($slide_ten);
var_dump($slide_ten[3][2][2][1]);
var_dump($slide_eleven);
var_dump($slide_twelve);
?>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
array(2) {
["cat"]=>
array(2) {
[0]=>
string(4) "cute"
[1]=>
string(5) "hairy"
}
["dog"]=>
array(2) {
[0]=>
string(5) "noisy"
[1]=>
string(9) "bark bark"
}
}
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
object(ArrayObject)#1 (1) {
["storage":"ArrayObject":private]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
object(ArrayObject)#2 (1) {
["storage":"ArrayObject":private]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
array(4) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
}
}
array(4) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
}
}
array(4) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
object(ArrayObject)#3 (1) {
["storage":"ArrayObject":private]=>
array(3) {
[0]=>
int(1)
[1]=>
string(3) "cat"
[2]=>
int(3)
}
}
}
}
}
string(3) "cat"
array(4) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
array(3) {
[0]=>
int(1)
[1]=>
int(3)
[2]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
}
}
}
array(3) {
["access"]=>
string(11) "my_function"
["title"]=>
array(3) {
["label"]=>
string(4) "fred"
["type"]=>
string(4) "text"
["access"]=>
NULL
}
["named_groupset"]=>
array(3) {
["field_one"]=>
array(3) {
["label"]=>
string(4) "fred"
["type"]=>
string(4) "text"
["access"]=>
NULL
}
["field_two"]=>
array(3) {
["label"]=>
string(4) "fred"
["type"]=>
string(4) "text"
["access"]=>
NULL
}
["field_three"]=>
array(3) {
["label"]=>
string(4) "fred"
["type"]=>
string(4) "text"
["access"]=>
NULL
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment