use array_slice
like this:
$_SESSION['A'] = array_slice($_SESSION['A'], 0, 2);
Update:
Also, for non sequential indexes we can create this function:
function array_pick($picks, $array)
{
$temp = array();
foreach($array as $key => $value)
{
if(in_array($key, $picks))
{
$temp[$key] = $value;
}
}
return array_values($temp);// or just $temp to keep original indexes
}