By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,747 Members | 2,011 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,747 IT Pros & Developers. It's quick & easy.

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

P: n/a
[PHP]
$successMsgArray = array('image' => array('add_album' => '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 $successMsgArray[$section][$action];
[/PHP]

Where the contents of $successMsgArray[$section][$action] will have
the "placeholders" replaced by their variable values, so if you want
to return $successMsgArray['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 MethodGeneratorForActionPerformer {

function &getSuccessMsg() { // STATIC STRING METHOD
global $section, $action, ${$section . 'LocationPath'},
$successMsgArray;
if (is_array($_POST) && @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 = ' . $successMsgArray[$section][$action]);
return $msg;
}

}
[/PHP]

Thanx
Phil
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
> 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.


You simply have a problem when creating the array:

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

should be

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

____________________________________
Wil Moore III, MCP | Integrations Specialist
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.