Helpful Information
 
 
Category: General Articles
Merge into $show

Hello everyone - here's a quick tip: I'm fond of giving my users a lot of controllable options using user profile fields and then using the phpinclude start template to express those as $show conditionals. I do this because it makes the resultant stylesheets more portable - the user profile field in the $bbuserinfo almost certainly will change from server to server - and if you refer to the same condition multiple times it becomes a pain in the tail to move the style to a new setup.

So I move the $bbuserinfo['fieldX'] stuff over to $show. The reason is that, like $bbuserinfo, $show is declared global in almost every function that deals with data display (the sole exception I know of is the function that parses subforums). You can also choose names for your show variables that are descriptive, which in turn makes your code easier for others to read.

Initialize your custom $show variables in your phpinclude_start template like so...


$show = array_merge($show,
'custom1',
'custom2',
);

And so on. After you initialize them, you can then assign their values. Changing the $bbuserinfo over into them - that's a lesson for another time (this is supposed to be a "quick tip") :)

I do this to, but as so to prevent some mess:

$loo_show = array(); // this array holds your custom show info
$show = array_merge($show, $loo_show); // merges custom show info into regular show array

Also everyone should be aware that array_merge changed in php version 5:

From php.net comments

As you know, guys, because of fixing bug #25494, starting from PHP 5.0.0 Beta2 the function doesn't accept scalar values as secondary arguments. It means if you try to run <? array_merge(array('array'),'scalar'); ?> the function throws a warning and returns <? NULL ?> instead of <? array(0=>'array',1=>'scalar');?>. If you want the old behavior of the merge function, use this instead:


<?
function array_merge_php4($array1,$array2){
$return=array();
foreach(func_get_args() as $arg){
if(!is_array($arg)){
$arg=array($arg);
}
foreach($arg as $key=>$val){
if(!is_int($key)){
$return[$key]=$val;
}else{
$return[]=$val;
}
}
}
return $return;
}
?>

Good stuff Michael. :)










privacy (GDPR)