Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the problem you're having is you're overwriting the <code>$message</code> with an array here:</p> <pre><code>$_SESSION[$type][$name] = $message; // Sets the message $_SESSION[$type][$name][$class] = $class; // Overwrites it with an array </code></pre> <p>All you'll need to do is save the message to the same array (and make sure the index you give it can never be the same as <code>$class</code> or <code>$dismiss</code>. So for example:</p> <pre><code>$_SESSION[$type][$name]['messagetext'] = $message; </code></pre> <p>Then, of course, update the display part of the code to use that index:</p> <pre><code>echo '&lt;div class="'.$_SESSION[$type][$name][$class].'"&gt;'.$_SESSION[$type][$name]['messagetext'].' '.$_SESSION[$type][$name][$dismiss].'&lt;/div&gt;'; </code></pre> <p>EDIT: After the discussion in the comments, the final code could look like this provided there is only going to be one message per <code>$type</code> and <code>$name</code> combination:</p> <pre><code>function flash($type = '', $name = '', $message = '', $class = '', $dismiss = '' ) { //We can only do something if name exists if($type) { //No message, create it if($message &amp;&amp; empty($_SESSION[$type][$name])) { $_SESSION[$type][$name]['message'] = $message; $_SESSION[$type][$name]['class'] = $class; $_SESSION[$type][$name]['dismiss'] = $dismiss; } //Message exists, display it else if($_SESSION[$type] &amp;&amp; empty($message)) { foreach($_SESSION[$type] as $name=&gt;$array) { echo '&lt;div class="'.$_SESSION[$type][$name]['class'].'"&gt;'.$_SESSION[$type][$name]['message'].' '.$_SESSION[$type][$name]['dismiss'].'&lt;/div&gt;'; } unset($_SESSION[$type]); } } } </code></pre> <p>Usage would be:</p> <pre><code>// set a message &lt;?php flash( 'error', 'test', 'whats up?', 'info', 'TRUE' ); ?&gt; // display all $type= 'error' messages &lt;?php flash( 'error' ); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload