You can easily add a new function to get array of z-values from line vertices.

1. Open *Function Editor* tab in *Field Calculator* (or *Expression*) window. Create a new function by clicking plus icon. Enter a file name, e.g. `z_array_from_line`.
2. Copy/Paste the script. Then, click `Save and Load Functions` (or related button) to register the function. It's added 'Custom' group.

        from qgis.core import *
        from qgis.gui import *

        @qgsfunction(args=0, group='Custom')
        def get_z_array_from_line_vertices(value1, feature, parent):
            z_array = [p.z() for p in feature.geometry().vertices()]
            return z_array

3. Now, you can use `get_z_array_from_line_vertices()` function in expressions.
                
The function gives you z-values in the same order as the vertices.