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');
Comments
Post a Comment