Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-05-2008, 06:52 PM   PM User | #1
Andy92
Regular Coder

 
Andy92's Avatar
 
Join Date: Nov 2005
Location: Horsham, West Sussex, UK
Posts: 363
Thanks: 7
Thanked 1 Time in 1 Post
Andy92 is an unknown quantity at this point
Help with php array

I need help with a php array.

At first, i had 2 sections on my website. Forums and Tutorials. This simple php script would get the forumid that you are on, pass it through all the possibly tutorial section forumid's, and determine if yu were viewing the forum, or the tutorials section...

PHP Code:
$filtered FALSE;
$filter   = array
(
'33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50',
);
$filter array_map'strtolower'$filter );

foreach ( 
$filter as $word )
{
    if ( 
strpos$forumid$word ) !== FALSE )
    {
        
$filtered TRUE;
        
$menututorials "tutorials2";
        
$menuforum "forum";
        break;
    } else {
        
$menututorials "tutorials";
        
$menuforum "forum2";
    }

Now that worked fine! But now i have 5 different sections, and i have tried to evolve that script, and it just doesnt work.

The 5 sections i have now are forum, resources, marketplace, tutorials and jobs. I have written this script below, but it just allways says that you are on the forum even if you are on other sections.

Can anyone pick up on whats wrong with it?

PHP Code:
$filtered FALSE;
$fresources = array
(
'11','51','52','53','54','55','56','57','58','59','60','61','62',
);
$fmarketplace = array
(
'25','26','27','28','63','64','65','66','67','68','69',
);
$ftutorials = array
(
'33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50',
);
$fjobs = array
(
'70','71','72','73','74','75','76',
);

$fresources array_map'strtolower'$fresources );
$fmarketplace array_map'strtolower'$fmarketplace );
$ftutorials array_map'strtolower'$ftutorials );
$fjobs array_map'strtolower'$fjobs );

foreach ( 
$fresources as $wresources )
foreach ( 
$fmarketplace as $wmarketplace )
foreach ( 
$ftutorials as $wtutorials )
foreach ( 
$fjobs as $wjobs )
{
    if ( 
strpos$forumid$wresources ) !== FALSE )
    {
        
$filtered TRUE;
        
$menuforum "forum";
        
$menuresources "resources2";
        
$menumarketplace "marketplace";
        
$menututorials "tutorials";
        
$menujobs "jobs";
        break;
    } else if ( 
strpos$forumid$wmarketplace ) !== FALSE ) {
        
$filtered TRUE;
        
$menuforum "forum";
        
$menuresources "resources";
        
$menumarketplace "marketplace2";
        
$menututorials "tutorials";
        
$menujobs "jobs";
        break;
    } else if ( 
strpos$forumid$wtutorials ) !== FALSE ) {
        
$filtered TRUE;
        
$menuforum "forum";
        
$menuresources "resources";
        
$menumarketplace "marketplace";
        
$menututorials "tutorials2";
        
$menujobs "jobs";
        break;
    } else if ( 
strpos$forumid$wjobs ) !== FALSE ) {
        
$filtered TRUE;
        
$menuforum "forum";
        
$menuresources "resources";
        
$menumarketplace "marketplace";
        
$menututorials "tutorials";
        
$menujobs "jobs2";
        break;
    } else {
        
$menuforum "forum2";
        
$menuresources "resources";
        
$menumarketplace "marketplace";
        
$menututorials "tutorials";
        
$menujobs "jobs";
    }

__________________
@Andy92 / Dribbble
Andy92 is offline   Reply With Quote
Old 08-05-2008, 07:25 PM   PM User | #2
malfist
Regular Coder

 
Join Date: May 2008
Posts: 188
Thanks: 7
Thanked 7 Times in 7 Posts
malfist is an unknown quantity at this point
what is this:
PHP Code:
$fresources = array
(
'11','51','52','53','54','55','56','57','58','59','60','61','62',
);
$fmarketplace = array
(
'25','26','27','28','63','64','65','66','67','68','69',
);
$ftutorials = array
(
'33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50',
);
$fjobs = array
(
'70','71','72','73','74','75','76',
); 
And this:
PHP Code:
foreach ( $fresources as $wresources )
foreach ( 
$fmarketplace as $wmarketplace )
foreach ( 
$ftutorials as $wtutorials )
foreach ( 
$fjobs as $wjobs 
Do you realize exactly what they're doing? Don't you think there's a better, more clear way? I don't see any comments either.
malfist is offline   Reply With Quote
Old 08-05-2008, 11:53 PM   PM User | #3
Andy92
Regular Coder

 
Andy92's Avatar
 
Join Date: Nov 2005
Location: Horsham, West Sussex, UK
Posts: 363
Thanks: 7
Thanked 1 Time in 1 Post
Andy92 is an unknown quantity at this point
I dont really know. I havent really learnt php arrays yet. But all the numbers are basically mapping out what forum id's are in each section, like resources, jobs etc, then it matches it against the forum id it has at the moment and determines what section you are on.

Can you help me?
__________________
@Andy92 / Dribbble
Andy92 is offline   Reply With Quote
Old 08-11-2008, 09:00 PM   PM User | #4
malfist
Regular Coder

 
Join Date: May 2008
Posts: 188
Thanks: 7
Thanked 7 Times in 7 Posts
malfist is an unknown quantity at this point
You shouldn't copy and paste code unless you understand what it's doing. The PHP site has a really good explanation about arrays, you should check it out.
malfist is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:52 AM.


Advertisement
Log in to turn off these ads.