JREAM
1/16/2014 - 6:16 PM

Already in Memory, No Splice!

Already in Memory, No Splice!

<?php
// This isn't really a bug, just a hiccup I ran into today

// I enumerated so it's easy to read :)
$data = [
    0 => ['data' => 'remove'],
    1 => ['data' => 'a'],
    2 => ['data' => 'b'],
    3 => ['data' => 'c']
];

echo '<pre>';

// $data is in memory it appears, once it is loaded in the foreach
foreach ($data as $_key => $_value)
{
    // Splicing the array of the first value (data => remove)
    array_splice($data, 0, 1);
    
    // It spliced the first item (array_splice is a &reference call)
    print_r($data);


    // Yet I can still access the single value :)
    echo "<hr>";
    echo $_value['data'];
    echo "<hr>";
}