Làm cách nào để duyệt qua một mảng nhiều chiều trong PHP?

Khi bạn có một mảng nhiều chiều, bạn có thể sử dụng cấu trúc

  1. // Recursively traverses a multi-dimensional array.

  2. function traverseArray[$array]

  3. // Loops through each element. If element again is array, function is recalled. If not, result is echoed.

  4. foreach[$array as $key=>$value]

  5. echo $key." = ".$value."
    \n";

05 để lặp qua mảng đó

Bạn cần sử dụng hai câu lệnh

  1. // Recursively traverses a multi-dimensional array.

  2. function traverseArray[$array]

  3. // Loops through each element. If element again is array, function is recalled. If not, result is echoed.

  4. foreach[$array as $key=>$value]

  5. echo $key." = ".$value."
    \n";

05 như trong đoạn mã sau

Chủ Đề