note 31640 added to function.array-pop
| From: | t0rus at dr dot com | Date: | Mon, 28 Apr 2003 23:18:29 +0000 |
| Subject: | note 31640 added to function.array-pop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-47226@lists.php.net to get a copy of this message | ||
//here's an example of how to check if the string has properly
//closed brakets for ex. if it has (())(()(())) or ))(())((()))))))
//using stack, returns true if the string is ok,
//and false otherwise
//it pushes "(" into stack if it finds it and pops it out if finds ")" after it
//i'm not used to programming in php so, don't mind the
//mistakes, if u've got any suggestions or questions go to my site - http://www.torsoft.tk
function validate ($string){
$Stack=array("");
array_pop($Stack);
$i=0;
while ($i<=strlen($string)){
$ft=substr($string,$i,1);
if ($ft=="(")
array_push($Stack,$ft);
elseif ($ft==")")
array_pop($Stack);
$i++;
}
return sizeof($Stack)==0;
}
--
http://www.php.net/manual/en/function.array-pop.php
http://master.php.net/manage/user-notes.php?action=edit+31640
http://master.php.net/manage/user-notes.php?action=delete+31640
http://master.php.net/manage/user-notes.php?action=reject+31640