A
A
Alex Ivanov2022-04-06 01:54:12
PHP
Alex Ivanov, 2022-04-06 01:54:12

How to iterate over a multidimensional array line by line?

Please tell me, there is an array m, collected from a group of checkboxes

m[2021][1]=1
m[2021][2]=1
m[2022][4]=1
m[2022][5]=1
m[2022][6]=1
m[2022][7]=1


array [
  2021 => array [
    1 => "1"
    2 => "1"
  ]
  2022 => array [   
    4 => "1"
    5 => "1"
    6 => "1"
    7 => "1"
  ]
]

you need to output them line by line in the form:
2021 - 1
2021 - 2
2022 - 4
2022 - 5
2022 - 6
2022 - 7


But something does not come to mind at all how to assemble such a cycle. Maybe there are ideas how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolay, 2022-04-06
@Protossan

If double nesting:

foreach ($arr1 as $year => $dataArr) {
  foreach($dataArr as $key => $value) {
    echo $year . ' - ' . $key;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question