Created
March 8, 2016 16:55
-
-
Save pvolyntsev/585470685af2434bb076 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Ответ на вопрос https://otvet.mail.ru/question/188209129 | |
*/ | |
$arr = array(1,2,3,0,4,5,6,0,8,9,10); // твой массив | |
$valueToFind = 0; // значение, которое надо найти | |
$valueFound = false; // найдено ли искомое значение | |
$sum = 0; | |
foreach($arr as $element) | |
{ | |
if (!$valueFound && $valueToFind==$element) // если искомое значение ранее не было найдено и тут на тебе! | |
{ | |
$valueFound = true; // запомнить какое что это произошло | |
continue; // и перейти к следующему | |
} | |
if ($valueFound) // если ранее искомое значение ранее уже было найдено | |
$sum += $element; // суммировать | |
} | |
echo $sum; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment