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?

1
  • files don't return things functions do Commented Jan 28, 2018 at 0:51

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.