Is there any built-in way to get an array's definition in string format? The out put should be valid PHP code for defining the same array.
For example:
$arrayDefinition = array_encode($anArray);
Should return something like:
['a' => 'x', 'b' => 'y']
I think you are looking for var_export()
.
Example:
$arr = [1,2,3];
echo $str = var_export($arr, TRUE);
output:
array ( 0 => 1, 1 => 2, 2 => 3, )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With