PHP - Array Suchfunktion
<?php
// Array Suchfunktion
function array_isearch($str, $array) {
$found = [];
foreach($array as $k => $v)
if (substr_count(strtolower($v), strtolower($str)) > 0) {
$found[] = $k;
}
return $found;
}
$search = 'Ipsum';
$compare = ['Lorem dolor', 'vitae turpis', 'natoque Ipsum augue',
'Fusce montes', 'Pellentesque ipsum lacinia', 'sit hendrerit ac vitae', ];
$results = array_isearch($search, $compare);
foreach($results as $key => $result) {
echo $compare[$result] . '<br>';
}
?>
Suche: Ipsum
Ausgabe:
natoque Ipsum augue
Pellentesque ipsum lacinia
Array Suchfunktion mit mehreren Begriffen
<?php
// Array Suchfunktion mit mehreren Begriffen
function array_isearch($str, $array) {
$found = [];
$parts = explode(" ", $str);
foreach ($parts as $part) {
foreach($array as $k => $v)
if (substr_count(strtolower($v), strtolower($part)) > 0) {
$found[$k] = $k;
}
}
return $found;
}
$search = 'Lorem Ipsum';
$compare = ['Lorem dolor', 'vitae turpis', 'natoque Ipsum augue',
'Fusce montes', 'Pellentesque ipsum lacinia', 'sit hendrerit ac vitae', ];
$results = array_isearch($search, $compare);
foreach($results as $key => $result) {
echo $compare[$result] . '<br>';
}
?>
Suche: Lorem Ipsum
Ausgabe:
Lorem dolor
natoque Ipsum augue
Pellentesque ipsum lacinia
Bausteine Alle Anzeigen
Eine zufällige Auswahl von Codeschnipseln
aus den Bereichen
HTML, CSS,
PHP, JavaScript und
MySQL.
<dd> Definitionsliste
CSS - Drehende E-Mail - Problem gelöst!