Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9266363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:18:03+00:00 2026-06-18T14:18:03+00:00

So I have the following code: $options = array( ‘navigation’ => array( ‘page_title’ =>

  • 0

So I have the following code:

$options = array(
    'navigation' => array(
        'page_title' => 'test',
        'menu_title' => 'test_title',
        'capabillity' => '',
        'menu_slug' => '',
        'function' => '',
        'icon_url' => '',
        'position' => '',
        'sub_menues' => array(
            array(
                'page_title' => 'test',
                'menu_title' => 'test_title',
                'menu_slug' => 'bla'
            ), 
            array(
                'page_title' => 'apples',
                'menu_title' => 'test_apples',
            ), // Set of Navigations
        )
    ),
    'settings' => array(
        array(
            'option_group' => 'bla',
            'option_name' => '',
            'sanitize_call_back' => ''
        )
    ),
    'core_template' => 'path/to/admin/template.phtml'
);

foreach($options as $setting=>$option){
    if($setting == 'navigation' && is_array($option)){
        foreach($option as $k=>$v){
            if(is_array($v)){
                foreach($v as $sub_menu){
                    foreach($sub_menu as $sk=>$sv){
                        if(isset($sub_menu[$sk])){
                            echo $sub_menu['menu_slug'];
                        }
                    }
                }
            }

            if(isset($option[$k])){
                echo $option['page_title'];
            }
        }
    }

    if($setting == 'settings' && is_array($option)){
        foreach($option as $settings_options){
            foreach($settings_options as $sk => $sv){
                if(isset($settings_options[$sk])){
                    echo $settings_options['option_group'];
                }
            }
        }
    }

    if($setting = 'core_template'){
        echo $options['core_template'];
    }
}

Which, yes is a mess and needs to be refactored, works UNTIL you throw in a variable that doesn’t exist. a good way to see this:

echo $sub_menu['menu_slug'];

now menu_slug exists in navigation/sub_menues/[0] array, but not in [1]array.

The typical way to fix this is:

if(isset($sub_menu['menu_slug'])){ // do something }

How ever as you can see from the navigation array, there is going to be A LOT of if is set do this, else do that. and I am looking for a cleaner and neater way where I can just do $sub_menu[‘something’] and it automatically checks to see if something exists and if so, returns its value, if NOT do nothing, just ignore it.

Now I have the right idea, where I do *if is set $sub_menu[$sk]* and then I could do:

echo $sub_menu[$sk]; 

the problem is I am calling a function in here that takes in arguments, the arguments are the values of the key, hence why I have to do $sub_menu[‘menu_slug’] for example.

So my question is:

How do I do something like:

some_function_call($sub_menu['menu_slug']);

with out having to do:

if(isset($sub_menu['menu_slug']) && isset($sub_menu['page_title']) /*...and so on...*/){
    some_function_call($sub_menu['menu_slug'], $sub_menu['page_title'] /*..and so on...*/);
}

The catch? – some options, such as (say for example) menu slug, might be optional.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:18:04+00:00Added an answer on June 18, 2026 at 2:18 pm

    Well, if you’re keys are unique relatively to all levels, you could do:

    array_walk_recursive($options, function($value, $key){
      if($value && in_array($key, array('menu_slug', 'page_title', 'option_group', 'core_template')))
        print $value;  
    });
    

    🙂

    But I assume that your real purpose is to wrap this text in HTML strings, so you should use switch instead of my if statement and print whatever you want. If you need to print the stuff in a certain order, use a temporary array to store the output you generate, and print it after you’re done.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I have the following code: <?php $this->beginWidget('zii.widgets.jui.CJuiDialog', array( 'id'=>'mydialog', // additional javascript options for
I have following code for alertdialog: AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this); helpBuilder.setTitle(Options); helpBuilder.setMessage(Choose Your
i have used the following code in .htaccess Options +FollowSymlinks RewriteEngine On RewriteBase /
I currently have the following js code function clearMulti(option) { var i; var select
I have the following function in my jQuery code: function checkUNSelectBox(item){ $('#DELETE option').each(function(){ <!--alert(item);-->
In the following code I have some comments in an array which are displayed
Here's a strange problem. I have the following javascript code: function doTransfer(target, source) {
i have the following code in a function char MenuOptions[7][200]; strcpy(MenuOptions[0], Create New /
I currently have the following lines of code in a script: set -A ARRAY

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.