Native function to filter array by prefix

Well, you could do it using preg_grep():

$output = preg_grep('!^car_!', $array);

You could use array_filter() too but you have to pass a test function into that.

Leave a Comment