php - Automatically replace values -
i have functions return different predifined values:
function a(){ $value = 'mercedes'; replacevalues($value); } function b(){ $value = 'audi'; replacevalues($value); } function c(){ $value = 'bmw'; replacevalues($value); }
is there function in php this:
function replacevalues($value){ switch($value){ case 'mercedes': echo $value = 'topa' break; case 'audi': echo 'topb' break //and on } }
it nice if define array have iterate through (or php function exists)
$a = array('mercedes'=>'topa', 'audi' => 'topb');
so expand array or change corresponding replacements.
regards
the function looking is: array_search
$array = array(0 => 'azul', 1 => 'rojo', 2 => 'verde', 3 => 'rojo'); $key = array_search('verde', $array); // $key = 2; $key = array_search('rojo', $array); // $key = 1;
Comments
Post a Comment