Created
November 8, 2021 04:38
-
-
Save sergioatanacio/5080798dfed148009550b4237cd89dde 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 | |
| if(! function_exists('lastElement')) | |
| { | |
| function lastElement($lastElement) | |
| { | |
| if(!is_array($lastElement) || $lastElement == []){ | |
| return []; | |
| } else{ | |
| return $lastElement[count($lastElement) - 1]; | |
| } | |
| } | |
| } | |
| if(! function_exists('popArray')) | |
| { | |
| function popArray($popFunction) | |
| { | |
| if (is_array($popFunction)) { | |
| array_pop($popFunction); | |
| return $popFunction; | |
| } else { | |
| return []; | |
| } | |
| } | |
| } | |
| function operation(string $operator, array $values, $result = null) | |
| { | |
| if($values === []) | |
| { | |
| return $result; | |
| } | |
| else | |
| { | |
| if ($result === null) | |
| { | |
| $values = array_reverse($values); | |
| $result = lastElement($values); | |
| $values = popArray($values); | |
| } | |
| $sendEvalResult = eval('return '.$result.' '.$operator.' '.lastElement($values).';'); | |
| return operation($operator, popArray($values), $sendEvalResult); | |
| } | |
| } | |
| echo(operation('.', [9, 2])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment