-1

For expample i have following code with one php script ,then part of html code and then again php script. When i use variable $v,that variable saves value for then next part of php code. How can i write script to purufy variable value for the next <?php invoke?

<html>
    <body>
        <?php
            $v = '1';
        ?>
        <div class="html-something">
        <div>
        <?php
            echo $v;//i want $v to be undefined
        ?>
    </body>
</html> 
azibom
  • 1,769
  • 1
  • 7
  • 21

1 Answers1

0

Hi
The whole PHP script is being executed at once and you cannot have a scope for it but if you want to simulate it behavior you can write a function like this and call it at the end of the your <?php ?> tags

function clear() {
    $vars = array_keys(get_defined_vars());
    foreach($vars as $var) {
        unset(${"$var"});
    }
}

And your code will be like this

<?php

// some php codes

clear()
?>
azibom
  • 1,769
  • 1
  • 7
  • 21