How can data attributes be utilized to improve code cleanliness in PHP and JavaScript integration?

Using data attributes can help improve code cleanliness by allowing us to store additional information directly within HTML elements. This can reduce the need for inline JavaScript or PHP code, making the code more readable and maintainable. By accessing these data attributes in our PHP and JavaScript code, we can easily retrieve and manipulate the stored data. PHP Code Snippet:

<div id="myElement" data-info="example"></div>

<?php
$info = '<script>document.getElementById("myElement").getAttribute("data-info");</script>';
echo $info;
?>