How can hidden variables be used to pass data between multiple forms in PHP?

To pass data between multiple forms in PHP, hidden variables can be used. Hidden variables are input fields in forms that are not visible to users but can store data that can be passed from one form to another. By setting the value of a hidden variable in one form and submitting it, the data can be accessed in another form.

// Form 1
<form action="form2.php" method="post">
  <input type="hidden" name="data" value="example_data">
  <input type="submit" value="Submit">
</form>

// Form 2 (form2.php)
<?php
if(isset($_POST['data'])){
  $data = $_POST['data'];
  echo "Data from Form 1: " . $data;
}
?>