What are the best practices for structuring text files to store data in PHP for easy retrieval and modification?

When structuring text files to store data in PHP for easy retrieval and modification, it is best practice to use a standardized format such as JSON or CSV. This allows for easy parsing and manipulation of the data within the file. Additionally, organizing the data in a logical and consistent manner will make it easier to retrieve specific information when needed.

// Example using JSON format
$data = array(
    "name" => "John Doe",
    "age" => 30,
    "email" => "johndoe@example.com"
);

// Encode the data array to JSON and write it to a file
file_put_contents('data.json', json_encode($data));

// Read the JSON data from the file and decode it back to an array
$data = json_decode(file_get_contents('data.json'), true);

// Access specific data elements
echo $data['name']; // Output: John Doe