How do I display this kind of 2-dim array value correctly?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Powell

    How do I display this kind of 2-dim array value correctly?

    [PHP]
    $successMsgArra y = array('image' => array('add_albu m' => 'Album:
    "$album" has been created',
    'edit_album' => 'Information for album "$album" has
    been changed'));
    [/PHP]

    I am having to return the following in a class method:

    [PHP]
    return $successMsgArra y[$section][$action];
    [/PHP]

    Where the contents of $successMsgArra y[$section][$action] will have
    the "placeholde rs" replaced by their variable values, so if you want
    to return $successMsgArra y['image']['add_album'] you should see:

    Album "Phil" has been created
    Where $album = 'Phil'

    instead of

    Album "$album" has been created
    How on earth do I do this? I have tried every combination of printf,
    sprintf, echo, and eval that there could be done, to no avail. I'm
    completely confused as to how to return this 2-dim array value into
    something readable.

    Here is the class method I have so far that fails miserably:

    [PHP]

    class MethodGenerator ForActionPerfor mer {

    function &getSuccessMsg( ) { // STATIC STRING METHOD
    global $section, $action, ${$section . 'LocationPath'} ,
    $successMsgArra y;
    if (is_array($_POS T) && @sizeof($_POST) > 0) foreach ($_POST as $key
    => $val) if (!isset(${$key} )) ${$key} = $val;
    $this->fileName = ($_POST['image_name']) ? $_POST['image_name'] :
    $this->fileName;
    echo eval('$msg = ' . $successMsgArra y[$section][$action]);
    return $msg;
    }

    }
    [/PHP]

    Thanx
    Phil
  • Guest's Avatar

    #2
    Re: How do I display this kind of 2-dim array value correctly?

    > How on earth do I do this? I have tried every combination of printf,
    sprintf, echo, and eval that there could be done, to no avail. I'm
    completely confused as to how to return this 2-dim array value into[color=blue]
    > something readable.[/color]

    You simply have a problem when creating the array:

    [PHP]
    $successMsgArra y = array('image' => array('add_albu m' => 'Album: "$album"
    has been created', 'edit_album' => 'Information for album "$album" has been
    changed'));
    [/PHP]

    should be

    [PHP]
    $successMsgArra y = array('image' => array('add_albu m' => "Album: $album has
    been created", 'edit_album' => "Informatio n for album $album has been
    changed"));
    [/PHP]

    _______________ _______________ ______
    Wil Moore III, MCP | Integrations Specialist


    Comment

    Working...