3v4l.org

run code in 300+ PHP versions simultaneously
<?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';

preferences:
28.97 ms | 404 KiB | 5 Q