1
I’m really bad at doing this kind of research and I don’t have much idea how to do it, the way I did I can only locate the word if written in full if it’s in sequence (from start to finish).
How can I locate by letters only instead of words by integers, being located anywhere in the sub-array names
?
<?php
$find = 'as'; //para localizar o 'foo bar bas' no sub array names na quarta posição
$directories = array (
'names' => array(
'hi',
'hello pt.stackoverflow',
'hello world',
'foo bar bas',
),
'dir' => array(
'directory 1',
'directory 2',
'directory 3',
'directory 4'
),
'type' => array(
'file',
'folder',
'file',
'folder'
)
);
$matches = preg_grep('/^'.$find.' (\w+)/i', $directories['names']);
$keys = array_keys($matches);
if(count($keys) != 0){
echo count($keys) . ' resultados encontrados </br>';
foreach($keys as $index) {
echo
$directories['names'][$index] . ' | ' .
$directories['dir'][$index] . ' | ' .
$directories['type'][$index] . '</br>';
}
}else{
echo 'Sem resultados para a busca ' . $find . '</br>';
}
?>