Skip to content
Advertisement

Using an array as request headers in PHP

I’m trying to send a GET request to an API using PHP stream_context_create and file_get_contents.

I need to add API keys to the headers of my request, I’m storing these in an array so I easily edit them later and use them in multiple functions. What is a good way to include these arrays as headers?

In this case the key of the array would be the header keys and the value of the array the value of the header.

Some code to explain the problem

JavaScript

Advertisement

Answer

Simply add the info to the header.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement