YES!
I'm very happy I've gotten to this point because this allowed me to make better usage of the function without having to (ab)use globals! Functions in PHP are a bit different then JavaScript (and I had been doing
lots of JavaScript especially in the past two months). Any way to me JavaScript functions were a way of doing something and that's it. However in PHP it's not
just a way of doing something but getting a reference based on the function. So as one can echo variables one can also echo functions! I don't know why PHP tutorials severely lack the usage of echo because in my book it will tell you exactly what is going on even if you're not getting an error message!
The
only thing I'm stumped on at the moment is that when there is not $_GET['audio'] set that my script echos 'audio' which I
do understand as being the last part of the function (
return $property;) however I'm not sure how to write the script in my mind to fall back to the default.
Or it could be somehow rewriting the foreach loop to only call the example() function in certain conditions.
But this is where has led me for now. Maybe I can beat you guys to a solution...heh maybe.

(solution being when $_GET['audio'] is not set it will echo as '0' and not as 'audio').
*edit* (It appears you can't conditionally return inside of {} within a function otherwise I would have moved on to the next step, or maybe I'm missing something in that regards?)
Code: Select all
<?php
$audio = '0';
function example($property)
{
if ($_SERVER['REQUEST_METHOD'] == 'GET')
{
if (isset($_GET[$property])) {$property = $_GET[$property];}
}
return $property;
}
$cookie_old = array(
'audio',
'connection',
'theme'
);
foreach ($cookie_old as $key => $value) {
example($value);
// Transition Preview IV cookies to Preview V
if (isset($_COOKIE[$value])) {setcookie($value, '', time()-60); $found = 1;}
// Create $variable
$$value = example($value);
}
?>
<html>
<head>
</head>
<body>
<div>
$audio = <?php echo $audio;?>
</div>
<div>
<a href="cookie6.php">No Request</a>
<br />
<a href="cookie6.php?audio=0">audio = 0</a>
<br />
<a href="cookie6.php?audio=1">audio = 1</a>
<br />
<a href="cookie6.php?audio=2">audio = 2</a>
</div>
</body>
</html>