Jump to content

Which is faster? Or Does it even matter?


Gayner

Recommended Posts

This code:

 

$styles = array();
	$d = dir('css');
	while (($entry = $d->read()) !== false)
	{
		if (substr($entry, strlen($entry)-4) == '.css')
			$styles[] = substr($entry, 0, strlen($entry)-4);
	}
	$d->close();

	// Only display the style selection box if there's more than one style available
	if (count($styles) == 1)
		echo "\t\t\t".'<div><input type="hidden" name="skinstyle" value="'.$styles[0].'" /></div>'."\n";
	else if (count($styles) > 1)
	{
		natsort($styles);

?>

<form action="index.php?auth_key=<?php echo $Profile['key']; ?>" method="post" name='theForm' onsubmit='return ValidateProfile()'>

						Select your Forum Style: <select name="skinstyle">
<?php

		while (list(, $temp) = @each($styles))
		{
			if ($user['skinstyle'] == $temp)
				echo "\t\t\t\t\t\t\t\t".'<option value="'.$temp.'" selected="selected">'.str_replace('_', ' ', $temp).'</option>'."\n";
			else
				echo "\t\t\t\t\t\t\t\t".'<option value="'.$temp.'">'.str_replace('_', ' ', $temp).'</option>'."\n";
		}

?>
						</select>
						<?php

	}

 

Or:

 

 

using this as PHP:

($Profile['skinstyle']=='0')? $i = "selected":""; ($Profile['skinstyle']=='1')? $i1 = "selected":"";($Profile['skinstyle']=='2')? $i2 = "selected":"";
($Profile['skinstyle']=='3')? $i3 = "selected":"";($Profile['skinstyle']=='4')? $i4 = "selected":"";($Profile['skinstyle']=='5')? $i5 = "selected":"";($Profile['skinstyle']=='6')? $i6 = "selected":"";
($Profile['skinstyle']=='7')? $i7 = "selected":"";

 

AND HTML FOR THAT:

  <select name="skinstyle">
<option value="0" $i>24-7GT Default</option>
<option value="1" $i1>Light Blue</option>
<option value="2" $i2>Sunset</option>
<option value="3" $i3>Beautiful Blue</option>
<option value="4" $i4>Tan</option>
<option value="5" $i5>Crazy Gray</option>
<option value="6" $i6>Toxin</option>
</select>

 

 

 

Which one is better? I created both btw.. but I created the second code first.. I recently made the top code so now I dont know which is better.. :) thanks

Link to comment
https://forums.phpfreaks.com/topic/169349-which-is-faster-or-does-it-even-matter/
Share on other sites

I'd keep it as you have it now

         while (list(, $temp) = @each($styles))
         {
            if ($user['skinstyle'] == $temp)
               echo "\t\t\t\t\t\t\t\t".'<option value="'.$temp.'" selected="selected">'.str_replace('_', ' ', $temp).'</option>'."\n";
            else
               echo "\t\t\t\t\t\t\t\t".'<option value="'.$temp.'">'.str_replace('_', ' ', $temp).'</option>'."\n";
         }

 

That is much more easer to read/maintain than this. This is why loops where invented :P

($Profile['skinstyle']=='0')? $i = "selected":""; ($Profile['skinstyle']=='1')? $i1 = "selected":"";($Profile['skinstyle']=='2')? $i2 = "selected":"";
($Profile['skinstyle']=='3')? $i3 = "selected":"";($Profile['skinstyle']=='4')? $i4 = "selected":"";($Profile['skinstyle']=='5')? $i5 = "selected":"";($Profile['skinstyle']=='6')? $i6 = "selected":"";
($Profile['skinstyle']=='7')? $i7 = "selected":"";

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.