fork download
  1. <?php
  2.  
  3. $i = 1;
  4. $arr = array("xyz" => array(1 => 3, 0 => "s"), "ds2" => array("a" => 96, "d" => 4), "foo" => array("test", "this"), "bar00" => array(0,1), "abc1" => array(2,3), "stack" => array("test", "arr"));
  5.  
  6. foreach ($arr AS $index => $value) {
  7.  
  8. // Assuming there are only 2 values, pop the last value
  9. $secondVal = array_pop($value);
  10.  
  11. echo "$index: $secondVal\n";
  12.  
  13. // Don't continue if 5 elements have been outputted
  14. if ($i >= 5)
  15. break;
  16.  
  17. $i++;
  18. }
  19.  
  20. foreach ($arr AS $index => $value) {
  21. // Remove the element if the index contains non-alpha characters
  22. if (preg_match('/[^A-Za-z]/', $index))
  23. unset($arr[$index]);
  24. }
  25.  
  26. print_r($arr);
  27.  
  28. ?>
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
xyz: s
ds2: 4
foo: this
bar00: 1
abc1: 3
Array
(
    [xyz] => Array
        (
            [1] => 3
            [0] => s
        )

    [foo] => Array
        (
            [0] => test
            [1] => this
        )

    [stack] => Array
        (
            [0] => test
            [1] => arr
        )

)