sea_1987 sea_1987 - 1 year ago 97
PHP Question

selecting an array key based on partial string

I have an array and in that array I have an array key that looks like,

this array key may change a little, so sometimes the page may load and the array key maybe
, I want to now is possible to just string match the array key up until the last
so that I can check what the value is after the last underscore?

Answer Source

one solution i can think of:

foreach($myarray as $key=>$value){
  if("show_me_" == substr($key,0,8)){
    $number = substr($key,strrpos($key,'_'));
    // do whatever you need to with $number...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download