TTTTTTTTTTTT - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of TTTTTTTTTTTT.php
- <?php
- $tokens = [3, 5, 3, 6, 1];
- $bots = ['A', 'B'];
- foreach($bots as $bot) {
- print_r(token_options($tokens));
- $tokens = [5, 3, 6, 1];
- }
- function top_option($tokens) {
- $options = token_options($tokens);
- }
- function token_options($tokens, $recursive = TRUE) {
- $index_first = array_key_first($tokens);
- $index_last = array_key_last($tokens);
- $options_indexes = [
- [$index_first],
- [$index_first, $index_first + 1],
- [$index_last],
- [$index_last - 1, $index_last],
- [$index_first, $index_last]
- ];
- $options = [];
- $values = [];
- foreach($options_indexes as $key => $indexes) {
- $k = $tokens;
- foreach($indexes as $index) {
- if (isset($tokens[$index])) {
- $values[$key]['options'][$index] = $tokens[$index];
- unset($k[$index]);
- }
- }
- if (!empty($values[$key]['options'])) {
- $values[$key]['options_sum'][$index] = array_sum($values[$key]['options']);
- if ($recursive) {
- $values[$key]['next_options'] = token_options($k, FALSE);
- }
- }
- }
- usort($values, function ($a, $b) {
- $a_sum = $a['options_sum'];
- $b_sum = $b['options_sum'];
- if ($a_sum == $b_sum) {
- return 0;
- }
- return ($a_sum < $b_sum) ? 1 : -1;
- });
- return $values;
- }
File Description
- TTTTTTTTTTTT
- PHP Code
- 12 Dec-2020
- 1.42 Kb
You can Share it:
Latest PHP Pastes