<?php function startsWith($haystack, $needle) { // search backwards starting from haystack length characters from the end return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE; } $example = array(); $example['variable'] = 'abc'; $nextToBeSet = 'var'; $is_exist = false; foreach($example as $k => $v) { if(startsWith($k, $nextToBeSet)) { $is_exist = true; break; } } if($is_exist) echo 'exists'; else echo 'not exists';
You have javascript disabled. You will not be able to edit any code.