Login | Sign up | Toll-Free: 1-800-752-0455
 
 

Forum

 

3 posts by 2 authors in: Forums > CMS Builder
Last Post: September 18, 2017

Anyone have suggestions on how to get an if statement to work within an array?

Below is a snippet of code showing what I'm trying to accomplish... thought what I have fails to work, but I think you'll get the idea.

    $sectionsToField = array(
        'news'                => 'title',
        'media'                => 'name',
    if ($site_settingsRecord['enable_events'] =='1' ) {
        'events'             => 'title',
    }
        'about'                => 'name',
        'products'            => 'name',
        'services'            => 'name',
    );

Thanks for any suggestions,

Zicky

Hi Zicky, 

There are a few ways to do that.  The simplest might be to add it afterwards.  How about this:

    $sectionsToField = array(
        'news'                => 'title',
        'media'                => 'name',
        'about'                => 'name',
        'products'            => 'name',
        'services'            => 'name',
    );

    if ($site_settingsRecord['enable_events'] == '1' ) {
        $sectionsToField['events'] = 'title';
    }

Let me know if that works for you!

Dave Edis - Senior Developer
interactivetools.com

Thanks Dave - works like a charm!