Web Design Forum: Loop to echo function using eval and incremental number - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Loop to echo function using eval and incremental number List of functions with 1 digit difference but how? Rate Topic: -----

#1 User is offline   WebTechGlobal 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 66
  • Joined: 15-June 09
  • Reputation: 0
  • Location:Fife
  • Experience:Intermediate
  • Area of Expertise:I'm Learning

  Posted 30 July 2009 - 05:41 PM

Hey this could be the sort of challenge someone likes if they have never done but. Right now I'm pretty much stuck however. If you look at the foreach loop below you will see that the function has $i at the end of it. I'm trying to use eval to make this happen but I get all the usual T Variable errors and unexpected characters etc



Anyone got any ideas? This is for a plugin, won't release details but if someone gives me a fix I'll put your name and site as a contributor permanent so you will get some traffic from it. Best I can do, cheers all.



foreach ($result as $result)
{

eval ('
function wpblogs_iframeadmin_sublevel_page_$i()
{ ?>
<iframe src ="http://www.webtechglobal.co.uk" width="100%" height="1700px">
<p>Your browser does not support iframes.</p>
</iframe>
<?php
}
');

$i++;
}
0

#2 User is offline   ElanMan 

  • In, out, shake it all about...
  • PipPipPipPipPip
  • View gallery
  • Group: Members
  • Posts: 3,298
  • Joined: 11-March 08
  • Reputation: 54
  • Gender:Male
  • Location:Darlington
  • Experience:Nothing
  • Area of Expertise:Nothing

Posted 30 July 2009 - 08:36 PM

Because you can use variable function names, I would do it something like this:
I wouldn't bother with eval() tbh
$i = 1;
foreach ($results as $result)
{
    $my_func_name = 'wpblogs_iframeadmin_sublevel_page_'.$i;
    $my_func_name()
        {
            #function code here...
        }

$i++;
} 

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users