- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Fastest way to store easily editable config data in PHP?
Serialize is better in comparison to JSON to store PHP variables.
The var_export can be used to save config file, and 'include' can be used to load the config file information.
This is an easy way to save config data programmatically and easier to read/write. Below is a sample code for the same −
return array( 'var_1'=> 'value_1', 'var_2'=> 'value_2', );
$config = include 'config.php'; $config['var_2']= 'value_3'; file_put_contents('config.php', '<?php return ' . var_export($config, true) . ';');
Instead of the above test.php, the below code can also be used −
$config = include 'config.php'; $config['var_2']= 'value_3'; file_put_contents('config.php', '$config = ' . var_export($config));
The updated config.php contains the following code −
return array( 'var_1'=> 'value_1', 'var_2'=> 'value_3', );
- Fastest Way to multiply two Numbers
- Fastest way to count number of rows in MySQL table?
- Best way to store weekly event in MySQL?
- Best way to store date/time in MongoDB?
- Fastest way to insert with multiple values in a single MySQL query?
- Fastest way of updating in MongoDB is update() or save()?
- Fastest way to search for a date from the date records in MySQL
- What is the fastest way to learn Python with real-time examples?
- What is the fastest way to update the whole document (all fields) in MongoDB?
- Fastest way to tell if two files have the same contents in Unix/Linux
- What's the fastest way to split a text file using Python?
- What is the easiest way to store date in MySQL database?
- Which is the fastest way to get a column's maximum value in MySQL?
- Simplest way to detect client locale in PHP
- How to store data in MySQL as JSON?