Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Biology Forums on December 18, 2014, 07:59:58 PM

Title: Serialize and array help...
Post by: Biology Forums on December 18, 2014, 07:59:58 PM
Let's say I have a variable

$var = 'a:2:{s:7:"replies";i:1;s:4:"icon";i:14;}';

When I unserialize $var, I get

print_r(unserialize($context['user']['filter_topic']));

Array ( [replies] => 1 [icon] => 14 )

How do I make an if statement for $var so that if $var contains only [replies] => 1 --> echo'Something';

Or

If $var contains both [replies] => 1 [icon] => 14, echo 'Something';

Thanks for reading.
Title: Re: Serialize and array help...
Post by: Arantor on December 18, 2014, 08:05:41 PM
Well.... could $var have anything else?

That said...

if (count($var) == 1 && isset($var['replies']))
{
  echo 'var only has the replies element in it';
}

if (count($var) == 2 && isset($var['replies'], $var['icon']))
{
  echo 'var has both replies and icon and nothing else';
}
Title: Re: Serialize and array help...
Post by: Biology Forums on December 18, 2014, 10:03:29 PM
Perfect, thank you :D