News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Serialize and array help...

Started by Biology Forums, December 18, 2014, 07:59:58 PM

Previous topic - Next topic

Biology Forums

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.

Arantor

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';
}


Advertisement: