Optimized convertToSingleArray, now accept also stdClass