I want to convert a big yaml file to PHP array source code. I can read in the yaml code and get back a PHP array, but with var_dump($array) I get pseudo code as output. I would like to print the array as valid php code, so I can copy paste it in my project and ditch the yaml.
We can use Ostream iterators to write to an output stream. The idea is to use an output iterator std::ostream_iterator to print array contents to std::cout with the help of std::copy , which takes input iterator to the starting and ending positions of the array and the output iterator.
To print an array in Python, use the print() function. The print() is a built-in Python function that takes the name of the array containing the values and prints it. To create an array in Python, use the numpy library and create an array using the np. array() function, and then print that array in the console.
You're looking for var_export
.
You could use var_export, serialize (with unserialize on the reserving end), or even json_encode (and use json_decode on the receiving end). The last one has the advantage of producing output that can be processed by anything that can handle JSON.
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