GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   PHP Experts, Optimization question (https://gfy.com/showthread.php?t=587728)

Brujah 03-17-2006 08:33 AM

PHP Experts, Optimization question
 
Looking to optimize a lengthy switch/case statement. Working on something like this, and considering how to optimize it and speed it up. It's not that slow yet but it might be when it's finished.

Code:

switch($var) {
  case 'val1':
      $action = 'step1';  break;
 case 'val2':
      $action = 'step2';  break;

 .. and so on for about 200 more of these ..

 default:
      $action = 'do the hokey pokey';  break;
}


Echo 03-17-2006 09:49 AM

if your $action are text/word try to put them in array() or store them in your database and call it in a limited query output

paterson3713 03-17-2006 10:15 AM

Yeah you could do like:
Code:

$actions['val1'] = 'step1';
$actions['val2'] = 'step2';

// Then,
$action = $actions[$var];

Or, like it was also mentioned before, using a database:
Code:

// First, put the values into a mysql database like: value | action
// Then,
$action = @mysql_result(mysql_query('SELECT action FROM mySteps WHERE value=\''.mysql_escape_string($var).'\''),0);


s9ann0 03-17-2006 10:53 AM

fuck that get your host to install a PHP cache!

mrkris 03-17-2006 11:08 AM

Quote:

Originally Posted by paterson3713
Yeah you could do like:
Code:

$actions['val1'] = 'step1';
$actions['val2'] = 'step2';

// Then,
$action = $actions[$var];

Or, like it was also mentioned before, using a database:
Code:

// First, put the values into a mysql database like: value | action
// Then,
$action = @mysql_result(mysql_query('SELECT action FROM mySteps WHERE value=\''.mysql_escape_string($var).'\''),0);


Never mix storage with procedure. The easiest thing to do, would be something like:

$method = 'some' . $action;
if (method_exists(array(&$object, $method))) {
$function->$method;
}

I would do something like that ...


All times are GMT -7. The time now is 11:54 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123