0

I have a php file that looks like the following

<?php

return [
    'first' => 'some value',
    'second' => 'blah blah',
];

I want to set the php output's array as a variable. So my variable is the actual array. I tried to do the following

$config = file_get_contents(__DIR__ . '/config.php');

However, that return the file content as a string.

How can $config be the returned array from my config.php file?

Junior
  • 11,602
  • 27
  • 106
  • 212

1 Answers1

1

You have to change the file, remove return and create assignment, like this:

$variable = [ ..... ]

Then if you need that array in different script, then use include or includerequire

PS: consider doing some basic tutorials on PHP. You are asking elementary question now and reinventing the wheel alone takes a lot of time.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141