PHP array assigning multiple keys to same value -


 $lang = array(         'thank you'=>'you welcome',         'thanks'=>'you welcome',         'thank ya'=>'you welcome'     ); 

as can see going tiresome writing multiple keys same value there way can do.

$lang['thanks']=>$lang['thank ya']=>$lang['thank you'] 

just trying save myself time here rewriting hundred times

php class function:

function fetch_key($key, $l,$bool){     $dynamic = new l18n;      if($bool == true or is_null($bool)){         return addslashes( $dynamic->convert($key,$l) );      }else{       return  $dynamic->convert($key,$l);      }   } 

ex

 $lang = array(         'thank you'=>'you welcome',         'thanks'=>'you welcome',         'thank ya'=>'you welcome',         'hello'=>'hello',         'goodbye'=>'goodbye'     );  

so i'd need make adds array , not fill key values same value when in fact aren't exact same. should have stated in beginning

you can use array_fill_keys() :

$keys = array('thank you','thanks','thank ya'); $lang = array_fill_keys($keys, 'you welcome'); 

example


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -