|
Joined: Feb 2002
Posts: 2,286
Veteran
|
Veteran
Joined: Feb 2002
Posts: 2,286 |
Hi, I can't find a way - but just wondered if this piece of code could be shortned in any way? <br /><br />elseif ( (strstr($user['U_Groups'], '-5-')) || (strstr($user['U_Groups'], '-501-')) || (strstr($user['U_Groups'], '-502-')) || (strstr($user['U_Groups'], '-522-')) ) {<br />$leaguelink = "<a href = \"$phpurl/conference\" $target>Conference Forums</a> | ";<br /><br /> I have curtailed the example above otherwise it would have been far too long - but essentially I could have 70 + groups that would result in the leaguelink being set to a particular URL. As I have 30 different possible links, I am going to have some very long lines in ubbt.inc.php - so just wondered if the string can be written better?
Fans Focus - Focusing on Fans of Sport (Okay - mainly football (the British variety at the moment - but expanding all the time....)
|
|
|
|
Joined: Apr 2002
Posts: 1,768
Addict
|
Addict
Joined: Apr 2002
Posts: 1,768 |
First of all, if you're using that if-condition more than once, write a function that returns true/false, so you don't have to duplicate code. function in_particular_groups($groups) {<br /> return<br /> strstr($groups, '-5-') or<br /> strstr($groups, '-501-') or<br /> ... ;<br />} Then you can do: elseif (in_particular_groups($user['U_Groups'])) {<br /> $leaguelink = "<a href = \"$phpurl/conference\" $target>Conference Forums</a> | "; I assume that the group numbers you're checking don't all start with "5" or something like that, so you can't do a regex match? Offhand I can't think of anything shorter, but if I think of anything I'll post it.
|
|
|
|
Joined: Feb 2002
Posts: 2,286
Veteran
|
Veteran
Joined: Feb 2002
Posts: 2,286 |
Thanks. No the groups vary.
I will look at the use of a function.
Fans Focus - Focusing on Fans of Sport (Okay - mainly football (the British variety at the moment - but expanding all the time....)
|
|
|
|
Joined: Apr 2002
Posts: 1,768
Addict
|
Addict
Joined: Apr 2002
Posts: 1,768 |
Here's another approach that may be more efficient: $particular_groups = array( <br /> 5, <br /> 501, <br /> 502, <br /> 522, <br />); <br /> <br />elseif (array_intersect(explode('-', $user['U_Groups']), $particular_groups)) { <br /> $leaguelink = "<a href = \"$phpurl/conference\" $target>Conference Forums</a> | ";
|
|
|
|
Joined: Feb 2002
Posts: 2,286
Veteran
|
Veteran
Joined: Feb 2002
Posts: 2,286 |
Thanks - some of that is new to me - so I will look into it.
Thanks.
Fans Focus - Focusing on Fans of Sport (Okay - mainly football (the British variety at the moment - but expanding all the time....)
|
|
|
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
|
|
Posts: 87
Joined: December 2001
|
|
Forums63
Topics37,573
Posts293,925
Members13,849
|
Most Online5,166 Sep 15th, 2019
|
|
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
|
|
|
|