Operations on multidimensional arrays in PHP