Skip to content

Instantly share code, notes, and snippets.

@kemalkanok
Created October 13, 2015 19:32
Show Gist options
  • Save kemalkanok/27062bd683e48a84ef37 to your computer and use it in GitHub Desktop.
Save kemalkanok/27062bd683e48a84ef37 to your computer and use it in GitHub Desktop.
function hierarch in system
<?php
function test($a = "test")
{
echo $a;
}
function search($word,$key)
{
for($i=0;$i<strlen($word);$i++)
{
if($word[$i] == $key)
{
echo $i;
break;
}
}
}
/**
* @param $word bütün kelime
* @param $key aradığım harf
*/
/*function searchMulti($word,$key)
{
$results = [];
for($i=0;$i<strlen($word);$i++)
{
if($word[$i] == $key)
{
$results[] = $i;
}
}
print_r($results);
echo count($results);
}*/
function searchOne($word,$key,$start = 0)
{
for($i=$start;$i<strlen($word);$i++)
{
if($word[$i] == $key)
{
return $i;
}
}
return -1;
}
function searchMulti($word,$key)
{
$data = [];
$start = 0;
while(searchOne($word,$key,$start) > -1)
{
$start = searchOne($word,$key,$start);
$data[] = $start;
$start = $start +1;
}
var_dump($data);
}
searchMulti('muhammet','m');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment