Building navigation structure for multiple users by adding values to multiple arrays at once I have a multidimensional array with associative values... I want to add some information to multiple arrays at the same time. Doing $array1=$array2=array(... seems to work but I'm worried that it's too easy. Will any array get extra data or have data overwritten by doing this?
What kind of unexpected behavior might I expect from this kind of code? Al should have 3 entries in it, while Bob and Chris will each have two... right? It seems to work, but I'm worried I'm overlooking something.

&lt;?    $content['Al'][]= array(
       "link"=&gt;"/admin.php",
       "text"=&gt;"Admin Login",
       "icon"=&gt;"wp.png");
    $content['Al'][]=$content['Bob'][]=$content['Chris'][] = array(
       "link"=&gt;"/Wordpress/wp-login.php",
       "text"=&gt;"Login to Wordpress",
       "icon"=&gt;"wp.png");
    $content['Al'][]=$content['Bob'][]=$content['Chris'][] = array(
       "link"=&gt;"/Gallery/Login.php",
       "text"=&gt;"Login to Gallery",
       "icon"=&gt;"picutres.jpg");



function userbox($heading,$contents){
    if($contents=="") return;
    echo "&lt;div class=\"refbox\"&gt;

            &lt;h2&gt;".$heading."&lt;/h2&gt;
            &lt;p&gt;";

    foreach ($contents as $key){
        if($key['link']!="")echo "&lt;a href=\"".$key['link']."\"&gt;";
        if($key['icon']!="")echo"&lt;img src=\"/images/icons/".$key['icon']."\" alt=\"".$key['text']."\" class=\"icons\"&gt;";
        echo $key['text'];
        if($key['link']!="")echo "&lt;/a&gt;";
        if($key['updated']!="")echo " &lt;span style=\"float:right;\"&gt;(".$key['updated'][0].")&lt;/span&gt;";
        echo "&lt;br&gt;";    
        }       
    echo "&lt;/p&gt;
        &lt;/div&gt;";    
}


?&gt;


Then in the content of the page I have

&lt;?userbox($user,$content[$user]);?&gt;


This should show a 'refbox' div with the users links in it within the page.
It works and I can't see any side effects, but it is unusual to see code like this, and I am not sure of the point of creating all 3 user arrays at once. 

Do you intend to display all 3 user menu options at the same time, or can only 1 user be logged in at once?

This is my preference for readability, also if you create a menu array and need items in a different order for different users, it would be difficult to achieve using the current code.

&lt;?php

function build_menu($user)
{
    // ### clearly show what each test is and what menu options are being set
    $menu = array();

    if ($user == 'Al') {
        $menu[] = array(
            "link" =&gt; "/admin.php",
            "text" =&gt; "Admin Login",
            "icon" =&gt; "wp.png");
    }

    if (in_array($user, array('Bob', 'Chris'))) {
        // menu options for multiple users can use in_array test
    }

    // default menu options for all users
    $menu[] = array(
        "link" =&gt; "/Wordpress/wp-login.php",
        "text" =&gt; "Login to Wordpress",
        "icon" =&gt; "wp.png");

    $menu[] = array(
        "link" =&gt; "/Gallery/Login.php",
        "text" =&gt; "Login to Gallery",
        "icon" =&gt; "picutres.jpg");

    return $menu;
}


function userbox($heading, $contents)
{
    // ### contents is supposed to be an array, why test it for being a blank string?
    // ### use {} to show scope
    if ($contents == "") {
        return;
    }

    // ### escape heading, what if it has html chars
    echo "&lt;div class=\"refbox\"&gt;

            &lt;h2&gt;" . htmlspecialchars($heading). "&lt;/h2&gt;
            &lt;p&gt;";

    /// ### think about your variable naming, $contents is actually menu items
    /// ### and $key is ambiguous, key of what?
    /// ### what if you used foreach ($menu_items as $menu_item) {

    foreach ($contents as $key) {

        // ### use {} around if statements, it is easier to see the scope of what is effected
        // ### use not empty instead of != "", that way if an array key doesn't exist like the 'updated' key below, your program won't generate a warning
        // ### use single quotes if you don't want to escape every double quote

        // if($key['link']!="")echo "&lt;a href=\"".$key['link']."\"&gt;";
        if (!empty($key['link'])) {
            echo '&lt;a href="' . $key['link'] . '"&gt;';
        }

        // ### i have given an example above, I will leave these ones for you to change
        if($key['icon']!="")echo"&lt;img src=\"/images/icons/".$key['icon']."\" alt=\"".$key['text']."\" class=\"icons\"&gt;";

        // ### escape html incase there are special characters
        // echo $key['text'];
        echo htmlspecialchars($key['text']);

        if($key['link']!="")echo "&lt;/a&gt;";
        if($key['updated']!="")echo " &lt;span style=\"float:right;\"&gt;(".$key['updated'][0].")&lt;/span&gt;";
        echo "&lt;br&gt;";
    }
    echo "&lt;/p&gt;
        &lt;/div&gt;";
}

$user = 'Al';
$menu = build_menu($user);
userbox($user, $menu);