Array


Array is a gathering of character, arrays or integers in order. Array in PHPoC consists of value and key. Key is only numbers starting from 0.

array001

<?php
    $int1 = 1;
    $char1 = 's';
    $str1 = 'sollae';
    $array1 = array(1, 2, 3);                 // array only with integer
    $array2 = array('a', 'b', 'c');           // array only with string
    $array3 = array($int1, $char1, $str1);    // array with mix of integers and string
?>
<?php
    $array1 = array(1, 2, 3);                 // define and initialize array
    $array1[0] = 5;                           // set the value of key 0 to 5
    echo $array1[0];                          // print the value of key 0
?>
[result]  
5
  • String and Array
    String can be used as array like examples below.
<?php
    $str = "test";                            // define a string variable
    $str[0] = 'T';                            // set the first character to T
    echo $str;
?>
[result]  
Test
  • Multi-dimension Array
    PHPoC supports multi-dimension array.
<?php
    $array0 = array(0, 1, 2);                             // one-dimension
    $array1 = array(3, 4, 5);
    $array2 = array($array0, $array1, array(6, 7, 8));    // two-dimension
?>