O
O
Olin2018-12-16 13:21:42
PHP
Olin, 2018-12-16 13:21:42

Push data into array....?

Tell me how to push data into an array ...
There is an array:

array('a' => array(array('aT' => '1', 'aS' => 'success'), array('aT' => '2', 'aS' => 'danger') ));

It is passed to the twig template, and there it is processed and a block is created from it:
{% for b in a %}
  {{ notice.input(b.aT, b.aS) }}
{% endfor %}

As a result, we get:
H-Qugalwh5E.jpg
As seen above - array('aT' => '1', 'aS' => 'success') in the array sets the text of the notification and its style.
Question: how to collect this array with a function?
That is, when calling alert('123', 'success'); did we get a notification on the page?
It worked with one notification, but if you call the function several times, the array will be overwritten and the last execution result will be displayed.
Or is there another way to organize the idea?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2018-12-16
@Rsa97

$alerts = [];
$alerts[] = alert(1, 'success');
$alerts[] = alert(2, 'danger');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question