0

I am trying to rewrite this for loop to remove the deprecated each()

for ($k = 0; (list($os_type, $os_score) = each($os_tab)) && ($k < $BBC_MAXOS); $k++) {

I am using a foreach loop which works except the iteration, I was wondering if there is a better way to iterate thru the loop. $BBC_MAXOS is set to 10 in the config but is not being honored.

foreach ($os_tab as $os_type => $os_score) {
    if ($k == 0) {
    $k < $BBC_MAXOS;
    $k++;
    } 
Steve C.
  • 47
  • 6
  • 1
    Are you just trying to limit the number of times the `foreach()` is executed - https://stackoverflow.com/questions/1656969/php-limit-foreach-statement – Nigel Ren May 17 '20 at 15:01
  • essentially yes. let me give this a shot see if it works thank you for the link – Steve C. May 17 '20 at 15:03
  • 1
    Are you setting the value of $k to 0 before the foreach statement? – mathius1 May 17 '20 at 19:37
  • Yes I set $k=0; just before the loop.. I added break to the condition and actually fixed the greater than sign and it worked ` if ($k == 0) { $k > $BBC_MAXOS break; $k++; } ` – Steve C. May 18 '20 at 20:07

0 Answers0