Testing PHP array operations

Simple array

Array Init

simple:                  Array
(
    [0] => GET
    [1] => POST
    [2] => PUT
    [3] => DELETE
)
 (4)

predefined:              Array
(
    [0] => HTTP
    [1] => FTP
    [2] => NNTP
    [3] => IRC
    [6] => FTPS
)
 (5) -- Notice empty slots

initialized:             html,head,body (3)
generated 1:             a,b,i,p,u:random:garbage (5)
generated 2:             hr,br,p,span,div (5)
original:                aa,bb,cc,gg,ee (5)
assigned:                aa,bb,cc,dd,zz (5)
function call by value:  F1,F2,F3 (3)
function return:         Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => Array
        (
            [0] => ff0
            [1] => F2
            [2] => F3
        )

)
 (4)
function call by ref:    ff0,ff1,F3 (3)
function return:         Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => Array
        (
            [0] => ff0
            [1] => ff1
            [2] => F3
        )

)
 (4)
multi-dimensional:       Array
(
    [0] => 3.1428571428571
    [1] => TLDs
    [2] => Array
        (
            [0] => com
            [1] => org
            [2] => net
            [3] => int
        )

    [3] => Array
        (
            [0] => edu
            [1] => mil
            [2] => gov
        )

    [4] => 42
)
 (5)

Array Access

PUT
NNTP
body
org
[1] is: FTP - set / not empty
[100] is:  - unset / empty

Array Operations

array:                   Array
(
    [0] => HTTP
    [1] => FTP
    [2] => NNTP
    [3] => IRC
    [6] => FTPS
    [7] => POP3
    [42] => Z1
    [43] => Z2
)

size:                    8
is_array:                TRUE
array addition:          Array
(
    [0] => edu
    [1] => mil
    [2] => gov
    [3] => int
)


sort:                    Array
(
    [0] => FTP
    [1] => FTPS
    [2] => HTTP
    [3] => IRC
    [4] => NNTP
    [5] => POP3
    [6] => Z1
    [7] => Z2
)
 (8) -- Empty elements removed
array_pop:               FTP,FTPS,HTTP,IRC,NNTP,POP3,Z1 (7) 'Z2' removed
array_reverse:           Z1,POP3,NNTP,IRC,HTTP,FTPS,FTP (7)
array_shift:             POP3,NNTP,IRC,HTTP,FTPS,FTP (6) 'Z1' removed
(replace) 0:             HTTPS,NNTP,IRC,HTTP,FTPS,FTP (6)
splice 1 2 s:            HTTPS,messaging,HTTP,FTPS,FTP (5) 'NNTP,IRC' removed
splice 3 1:              HTTPS,messaging,HTTP,FTP (4) 'FTPS' removed
splice 1 0 s s:          HTTPS,POP3,IMAP4,messaging,HTTP,FTP (6) '' removed
push Y Z:                HTTPS,POP3,IMAP4,messaging,HTTP,FTP,Y,Z (8)
unshift A B:             A,B,HTTPS,POP3,IMAP4,messaging,HTTP,FTP,Y,Z (10)
array_slice 2 4:         HTTPS,POP3,IMAP4,messaging (4)
array_slice 6:           HTTP,FTP,Y,Z (4)
array_slice 2 -2:        HTTPS,POP3,IMAP4,messaging,HTTP,FTP (6)
array_merge a1 a2:       HTTPS,POP3,IMAP4,messaging,HTTP,FTP,GET,POST,PUT,DELETE,html,head,body (13)
in_array:                HTTP: TRUE, DEL: FALSE (only full match), http: FALSE (case sensitive)
array_search:            HTTP: 4, DEL:  (only full match), http:  (case sensitive)
implode ' | ':           HTTPS | POP3 | IMAP4 | messaging | HTTP | FTP | GET | POST | PUT | DELETE | html | head | body

Array Iteration

foreach:                 [0] HTTPS, [1] POP3, [2] IMAP4, [3] messaging, [4] HTTP, [5] FTP, [6] GET, [7] POST, [8] PUT, [9] DELETE, [10] html, [11] head, [12] body, 
for:                     [0] HTTPS, [1] POP3, [2] IMAP4, [3] messaging, [4] HTTP, [5] FTP, [6] GET, [7] POST, [8] PUT, [9] DELETE, [10] html, [11] head, [12] body, 

Associative array

Associative Array Init

simple:                  one=1, two=2_2, three=3_3_3, #@!\%=garbage (4)
literal:                 one=un_uno_ichi, two=deux_dos_ni, three=trois_tres_san, and... more=... (4)
id:                      one=1, un=1, uno=1, ichi=1 (4)
val:                     Array
(
    [1] => 1
    [] => Array
        (
            [one] => 1
            [un] => 1
            [uno] => 1
            [ichi] => 1
        )

    [2] => 2
    [12345] => Array
        (
            [0] => 4
            [1] => 2
        )

    [12346] => in numerical slot
    [3] => Array
        (
            [0] => aa
            [1] => bb
            [2] => cc
            [3] => dd
            [4] => zz
        )

    [0] => 12345
)
 (7)
nested:                  Array
(
    [deep] => Array
        (
            [into] => Array
                (
                    [array] => !
                )

        )

)
 (1)

Associative Array Access

2_2
3_3_3
garbage


1
1
!

Associative Array Operations

(add):                   one=un_uno_ichi, two=deux_dos_ni, three=trois_tres_san, and... more=..., newOne=New entry, 1=1, +-/*=ops (7)
(delete) unset:          one=un_uno_ichi, three=trois_tres_san, newOne=New entry, +-/*=ops (4)
merge:                   one=1, two=2_2, three=3_3_3, #@!\%=garbage, newOne=New entry, +-/*=ops, un=1, uno=1, ichi=1, deep=Array (10)
shuffle:                 0=1, 1=1, 2=3_3_3, 3=2_2, 4=ops, 5=1, 6=New entry, 7=garbage, 8=1, 9=Array (10)
sort:                    0=1, 1=1, 2=2_2, 3=3_3_3, 4=New entry, 5=garbage, 6=ops, 7=1, 8=1, 9=Array (10)


View source of this page