1bigbear Posted November 3, 2009 Share Posted November 3, 2009 Hi, I have a foreach $verify="a"; foreach ($value as $each) if ($each == $verify) { function strange( $text) { // do something } }} the error: Fatal error: Cannot redeclare strange But I have to use the strange function on each iteration of the array. How to solve this problem? Link to comment https://forums.phpfreaks.com/topic/180103-solved-cannot-redeclare-function-in-foreach/ Share on other sites More sharing options...
Mchl Posted November 3, 2009 Share Posted November 3, 2009 Declare it before loop. Link to comment https://forums.phpfreaks.com/topic/180103-solved-cannot-redeclare-function-in-foreach/#findComment-950106 Share on other sites More sharing options...
taquitosensei Posted November 3, 2009 Share Posted November 3, 2009 you could declare strange at the begining of your php page then return a value. Then just call it in your loop. // this is the beginning of your page function strange($text) { // do something return $something; } then in your loop foreach($value as $each) { if($each==$verify) { $something=strange($text); } } Link to comment https://forums.phpfreaks.com/topic/180103-solved-cannot-redeclare-function-in-foreach/#findComment-950107 Share on other sites More sharing options...
1bigbear Posted November 3, 2009 Author Share Posted November 3, 2009 Your right thanks Link to comment https://forums.phpfreaks.com/topic/180103-solved-cannot-redeclare-function-in-foreach/#findComment-950115 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.