if your array is always going to have only two dimensions, you might use this: $finalArray = array(); ...
stackoverflow.com