loops - Iterate on PHP variable (list/array) then output the index based on its value -


using following example in php:

$priv['page_a'] = 11; $priv['page_b'] = 22; $priv['page_c'] = 33; $priv['page_d'] = 44; 

1) iterate on 4 values in $priv. 'foreach' correct way it?

2) if value higher given number, echo index of value. not sure how it. comparaison must int (not string).

ex. using "30" output:

page_c page_d 

is possible? or maybe not using correct container i'm trying ?

ps. how call type of "$priv" in example ? array ? indexed variable ? dictionary ? list ?

thank you.

basically:

<?php function foo($var){      $priv['page_a'] = 11;     $priv['page_b'] = 22;     $priv['page_c'] = 33;     $priv['page_d'] = 44;      $out='';     foreach ($priv $k=>$v){          if ($v >$var){             $out .= $k.'<br>';         }     }   return $out; } echo foo('30'); 

demo: http://codepad.viper-7.com/gnx7gf


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -