Skip to content
Advertisement

Is PHP possible to print out variable source code as string?

I have a simple variable like this

JavaScript

Now, PHP comes with several print out function

print_r

JavaScript

result:

JavaScript

var_dump

JavaScript

result:

JavaScript

I want a function that can print out the original source code like this:

JavaScript

result:

JavaScript

Is there any function that can achieve this?

Advertisement

Answer

This should work for the exact “restore array” you’re asking.

Try “var_export” and “eval”:

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