PHP technical round interview Question part 2

preview_player
Показать описание
In technical round of php, interviewer expect interviewee should have knowledge of basic php functions. we solving quetions using most asked and utilized php string and array functions. aim of this video is practice of functions to clear technical round question.
Рекомендации по теме
Комментарии
Автор

You did the VERY hard way ... here is a MUCH easier and less code way:
$string = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been around five centuries. It has survived not only five centuries, remaining essentially unchanged.';
$output = ['a'=>0, 'e'=>0, 'i'=>0, 'o'=>0, 'u'=>0];
$string_split = str_split($string);
$values =
foreach($output as $key=>$val) {
if(array_key_exists($key, $values)) {
$output[$key] = $values[$key];
}
}
echo'<pre>';
print_r($output);
echo'</pre>';
-- Result:
Array
(
[a] => 7
[e] => 19
[i] => 14
[o] => 6
[u] => 9
)

scottgeithman
Автор

Maybe you can solve it easier in 5 lines of code:

$loremIpsum = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged";
$vowelArray = ["a" => 0, "e" => 0, "i" => 0, "o" => 0, "u" => 0];
foreach ($vowelArray as $key => &$value) {
$value = substr_count($loremIpsum, $key);
}
print_r($vowelArray);die();

adria