0

I' am currently stuck in a issue where merged array only showing first array on dump. Attached is the image of the dump.

Array Dump

As you can see the first (index 0) array comes out really well, but the second and third array are not in correct array format.

This function appends array to $add_admin_menu variable

$add_admin_menu = array();
  function add_admin_menu( $args ) {
    global $add_admin_menu;
    if( !empty($add_admin_menu) ){
      $arg1 = $add_admin_menu;
      return $add_admin_menu = array_merge($arg1, $args);
    } else {
      return $add_admin_menu = array($args);
    }
}

This function just calls the variable $add_admin_menu and makes it into a function

function get_admin_menu(){
  global $add_admin_menu;
  return $add_admin_menu;
}

**This is how I call the function add_admin_menu and pack array inside it **

$args1 = array("Dashboard", "dashboard.php", "dashboard");
add_admin_menu($args1); 

$args2 = array("Posts", "posts.php", "posts");
add_admin_menu($args2); 

$args3 = array("Pages", "pages.php", "pages");
add_admin_menu($args3);

$get_admin_menu = get_admin_menu();
echo "<pre>";
print_r( $get_admin_menu );
echo "</pre>";
3
  • Why -1, whats wrong with the question? Commented Jun 25, 2014 at 8:59
  • What happens if you do: if( !empty($add_admin_menu) ){ $arg1 = $add_admin_menu; array_push($add_admin_menu, $args); } Commented Jun 25, 2014 at 8:59
  • @Darren :: I' am getting the same result. Commented Jun 25, 2014 at 9:01

1 Answer 1

2

You have to change this:

return $add_admin_menu = array_merge($arg1, $args);

to this:

return $add_admin_menu[] = $args;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.