Jump to content

variable standards?


CyberShot

Recommended Posts

I am working in wordpress. I am using a switch statement to call a php page. It looks like this

 

$slider_type = $options['type'];
	switch($slider_type) { 
		case "Half Page Slider" :
			include('nivo-default.php');
			break;
		case "Full Page Slider" :
			include('nivo-fullpage.php'); 
			break;	
		default:
			include('nivo-fullpage.php');			
	}

 

The code works fine. My question is this. I want to use the exact same code to call the css file that runs each page. So instead of inlcuding a php page, I would replace that with the css call. So is it a bad idea to use the variables in the head section and then again in the page a little further down? or should I change the names? What is the best coding practice here?

Link to comment
https://forums.phpfreaks.com/topic/234198-variable-standards/
Share on other sites

Well, it depends on the contents of the variable and what you are going to use it for.

 

If it needs to be filtered and/or modified in some way, assigning a new variable to it would be best. This is only so you can use the original contents again, for some other purpose.

Then, you would then destroy the newly assigned variable after you used it to save memory. But if the type and form of the contents doesn't matter, using the original variable would be preferred.

 

Most of these "standards", or so-called ones, come into play at a microsecond scale. At normal levels, the only reason you would actually need to destroy variables to free up memory, is when you are working with large arrays or lists(something maybe such as a file/image).

 

I don't see any variables being introduced into the example switch statement you provided, though, so I cannot propose anything for that?

 

 

Link to comment
https://forums.phpfreaks.com/topic/234198-variable-standards/#findComment-1203766
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.