Лехин Код - 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.



Your result can be seen below.

Result of php executing





Full code of Лехин Код .php

  1. <?php
  2.  
  3. class Current {
  4.     public $next;
  5.     public $value;
  6. }
  7.  
  8. function init() {
  9.     $root = new Current();
  10.     $c = $root;
  11.     for($i=1;$i<5;$i++){
  12.         $c->next = new Current();
  13.         $c->value = $i;
  14.         $c=$c->next;
  15.     }
  16.     return $root;
  17.     
  18. }
  19.  
  20. // function print_c($current){
  21. //     while ($current) {
  22. //         print("\$current->val = {$current->val}")
  23. //     }
  24. // }
  25.  
  26. function rev($current) {
  27.     $prev = null;
  28.     while ($current) {
  29.         $next = $current->next;
  30.         $current->next = $prev;
  31.         $prev = $current;
  32.         $current = $next;
  33.     }
  34.     return $prev;
  35. }
  36.  
  37.  
  38.  
  39. function app(){
  40.     $test = init();
  41.     print_r($test);
  42.     $rev = rev($test);
  43.     print_r($rev);
  44. }
  45. app();
  46.  
File Description
  • Лехин Код
  • PHP Code
  • 03 Jun-2021
  • 703 Bytes
You can Share it: