XF 1.5 Conditionals 101: How Can I search a comma delimited string for a value?

king8084

Well-known member
my var has the following stored:

"28,34,36,43,55,69,71,86,100,105,114,125"

how can i identify if "86" is in this list? in_array hasn't seemed to work, nor an ==. I've been searching ad nauseam here + google and i must be doing something terribly wrong because I can't seem to find an answer to a seemingly easy question.

Thanks.
 
Last edited:
The absolute easiest way is...

Code:
$values = "28,34,36,43,55,69,71,86,100,105,114,125";

$result = in_array(86, explode(',', $values));
 
The absolute easiest way is...

Code:
$values = "28,34,36,43,55,69,71,86,100,105,114,125";

$result = in_array(86, explode(',', $values));
hmm it's not liking the syntax of that. tried with/without the semi-colon + using {} around the values, plus '' around the 86... no luck.
 
FWIW it can be done in XF2 but not XF1:
Code:
<xf:if is="in_array(86, $var|split)">
XF1 does support in_array but it doesn't have any function to explode a string to an array. So your only real option is to make sure your variable is already converted to an array. If it is, then you can do:
Code:
<xen:if is="in_array(86, $var)">
 
XF1 does support in_array but it doesn't have any function to explode a string to an array. So your only real option is to make sure your variable is already converted to an array. If it is, then you can do:
arghh. i'm not sure that it is converted to an array already.. i'll have to dig through the mod that sets the var, unless there's a better way to confirm that? i'm guessing no, as i wasn't able to get the in_array function work in xen.

...if not, then am i hosed entirely? this seems elementary to be able to do
 
was a custom mod that was made a while ago. lives in $visitor.secondary_group_ids, spits out as the string in op.
So you're checking if the member is a member of a user group?

You want..
Code:
{xen:helper ismemberof, $visitor, '86'}

I don't recall if the ' ' is needed around the 86 or not.
 
So you're checking if the member is a member of a user group?

You want..
Code:
{xen:helper ismemberof, $visitor, '86'}
oh, yikes.

...nothing to see here.

that definitely did the trick. over-engineering at it's best right here.

cancel the search party -- appreciate everyone's input!!
 
I did wonder about asking you whether it was related to user groups...

Next time if you have a similar question, try to expand on exactly what you're doing as often that can lead to simpler solutions - glad it was as simple as using the built-in helper though.
 
Top Bottom