nostalgy - 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 nostalgy.php

  1. <?php
  2. $str="))";
  3. $i=0;
  4. $stack=array();
  5. $top=-1;
  6. $flag=true;
  7. while ($i<strlen($str)){
  8.     if ($str[$i]=='(' || $str[$i]=='{' ||$str[$i]=='[')
  9.         {
  10.             $top++;
  11.             $stack[$top]=$str[$i];
  12.         }
  13.         else {
  14.             if ($top==-1) {echo 'NO'; $flag=false;break; }
  15.         if (($str[$i]==')' && $stack[$top]=='(') ||($str[$i]=='}' && $stack[$top]=='{') ||($str[$i]==']' && $stack[$top]=='['))
  16.                 $top--;
  17.             else{
  18.                 echo 'NO'; $flag=false;break; }
  19.             
  20.         }
  21.         $i++;
  22. }
  23. if ($flag==true && $top==-1)
  24.     echo 'YES';
  25. else
  26.     echo 'NO';
  27.  
File Description
  • nostalgy
  • PHP Code
  • 10 Jun-2020
  • 612 Bytes
You can Share it: