Use netlify environment variables in PHP Project

I am using netlify to deploy the same project multiple times.

How can I write the environment variable into a file as described?

After reading through tons of documentation I found this:

As a very small example workflow, we could “pass on” the $CONTEXT variable into a file that you can access at browse time, like this, during build:

npm run build && echo $CONTEXT > public/netlify-context.txt

I think this is the way to go