Created
January 2, 2017 09:50
-
-
Save georgo/6fa285df5e1c3a3d3ea5c271afea90d6 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 | |
| function equilib(&$arr) { | |
| $left = array_sum($arr); | |
| $right = 0; | |
| foreach($arr as $index => $value) { | |
| $left -= $value; | |
| if ($left == $right) { | |
| return $index; | |
| } | |
| $right += $value; | |
| } | |
| return -1; | |
| } | |
| $arr = [-7, 1, 5, 2, -4, 3, 0]; | |
| echo equilib($arr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment