Ya dizinin tüm hatları üzerinde döngü ve her dize strpos
kullanmak; Bu gibi biraz:
$search_string = '<div>1</div>';
$array = array(
'sample' => '<div>1</div><p>fish food</p>',
'sample2' => '<div>2</div><p>swine</p>'
);
foreach ($array as $key => $string) {
if (strpos($string, $search_string) === 0) {
var_dump($key);
}
}
Size arama dizesi ile başlayan satırın anahtarını alacak olan:
string 'sample' (length=6)
Or preg_grep might do the trick too :
Returns the array consisting of the
elements of the input array that
match the given pattern .
Örneğin:
$result = preg_grep('/^' . preg_quote($search_string, '/') . '/', $array);
var_dump($result);
(Don't forget to use preg_quote
! )
Alacak:
array
'sample' => string '<div>1</div><p>fish food</p>' (length=28)
, Bu şekilde Not, anahtarı almak, ama hattı sadece içeriği değil.