Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder Andy92's Avatar
    Join Date
    Nov 2005
    Location
    Horsham, West Sussex, UK
    Posts
    363
    Thanks
    7
    Thanked 1 Time in 1 Post

    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";
        }


  • #2
    Regular Coder
    Join Date
    May 2008
    Posts
    187
    Thanks
    7
    Thanked 7 Times in 7 Posts
    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.

  • #3
    Regular Coder Andy92's Avatar
    Join Date
    Nov 2005
    Location
    Horsham, West Sussex, UK
    Posts
    363
    Thanks
    7
    Thanked 1 Time in 1 Post
    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?

  • #4
    Regular Coder
    Join Date
    May 2008
    Posts
    187
    Thanks
    7
    Thanked 7 Times in 7 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •