Hello! The goal is to produce a random phrase on the page from the array and count how many times it was displayed on the screen. To store the number of repetitions, I decided to use a number that is stored in an array with this phrase. And if the random number matches the key, take this variable, increment by one and put it back. The problem is that the number in the array is overwritten only once, and then again equal to the initial value. I understand that the array is reinitialized with the original values. Is this true and how can I fix it to work? Code below:
<?php $phrases = array( 1 => array ('phrase' => 'И один в поле воин!', 'number' => 0, ), 2 => array ('phrase' => 'Под лежачий камень вода не течет.', 'number' => 0, ), ); $from = 1; $to = count($phrases); $rand = rand($from, $to); foreach ($phrases as $key => $value) { if ($rand == $key){ $i = $phrases[$key]["number"]; $i++; $phrases[$key]["number"] = $i; echo $value["phrase"]." повторялось ".$phrases[$key]["number"]." раз"; } } ?>