Each set is then divided as variable/values by periods.
So I'm trying to match only and exactly (===) the $property to the variable and return it's value (return to stop the foreach loop from continuing).
To you an idea of the desired results...
echo example('audio') should echo '7'
echo example('backgroundimages') should echo 'z'
echo example('browserpatch') should echo '11'
echo example('chatroom') should echo '0'
I'm thinking off hand I could either do a partial preg_match and then just explode and return the value though that seems sort of cheap maybe? I wouldn't be asking these questions if I wanted the cheap way out though.
Code: Select all
<?php
function example($property)
{
$cookie = 'audio.7_backgroundimages.z_browserpatch.11_chatroom.0_connection.0_css3.0_cursors.0';
$pieces = explode('_', $cookie);
foreach($pieces as $key=>$value)
{
$value = explode('.', $value);
${$value[0]} = $value[1];
return $value[1];
}
}
echo example('audio');
?>(If you're following my critique thread you'll be pleasantly pleased by the lack of globals once I get this working