Return to Snippet

Revision: 4526
at December 30, 2007 18:32 by engel


Initial Code
<?php

function strstr_array( $haystack, $needle ) {
	if ( !is_array( $haystack ) ) {
		return false;
	}
	foreach ( $haystack as $element ) {
		if ( strstr( $element, $needle ) ) {
			return $element;
		}
	}
}

function stristr_array( $haystack, $needle ) {
	if ( !is_array( $haystack ) ) {
		return false;
	}
	foreach ( $haystack as $element ) {
		if ( stristr( $element, $needle ) ) {
			return $element;
		}
	}
}

?>

Initial URL


Initial Description
Searches an array $haystack for $needle. Returns the value of the element which contains the first result. Use strstr_array() for case-sensitive searches and stristr_array() for case-insensitive searches.

Initial Title
strstr() and stristr() with Arrays

Initial Tags
array

Initial Language
PHP