I have searched for a solution to this problem and many answers I read said it is not possible.
I found this way and it worked. Let me know if it is a bad way of doing it.
<?php echo '<script>
document.getElementById("displayLSValueThroughPHP").innerHTML =
JSON.parse(localStorage.getItem(\'localStorageValue\'))</script>';?></div>```