$ret[$j][$i] = $tmp[i]; #just changed to square brackets