Parse output of Google Cloud command into PHP associative array
This code is complicated, and likely buggy.


If a line does not end in a space character, then the last word on that line will be ignored.
The output of gcloud compute instances list is a table.  For example:

NAME                                             ZONE          MACHINE_TYPE   PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP     STATUS
gke-cluster-asia-eas-default-pool-dc8f484c-knbs  asia-east1-a  n1-standard-1               10.140.0.2   104.155.227.25  RUNNING
gke-cluster-asia-eas-default-pool-dc8f484c-x8cv  asia-east1-a  n1-standard-1               10.140.0.3   104.199.226.16  RUNNING
gke-cluster-asia-eas-default-pool-dc8f484c-z5wv  asia-east1-a  n1-standard-1               10.140.0.4   104.199.134.9   RUNNING


If the table contains an empty value (such as for the "PREEMPTIBLE" column above), then the turn_linux_row_to_array() function will ignore it, resulting in a mismatch between the headers and the values.


I don't recommend trying to improve this code.  Instead, noting that all Google Cloud commands accept a --format option, you should choose a format that is easy to parse.  I would recommend replacing the entire code with:

$servers = json_decode(shell_exec('gcloud compute instances list --format=json'), true);


… to take advantage of json_decode().  That's it — you're done!