Format address fields to remove blank lines

I am working on a pdf of a certificate that has four address fields and a postcode field. I want to be able to move the fields up if one or more of the address fields are blank or null.

I have tried to work with an array_filter on an On Record event but have had no success. Does anyone know of a good solution?

All sorted. I had not taken account of the array key which I was using to retrieve the data. Used array_values() to re-index fixed the problem.