amitchhajer
amitchhajer

Reputation: 12830

how to use foreach for 3d arrays in php

I have a 3d array and needs to do something with it, was able to solve the problem using simple for each like this:

for($n=0;$n<count($d["T"]);$n++)
{
 $d["T"][$n]["Pay"]=number_format($d["T"][$n]["Pay"], 2, '.', '');
}

Upvotes: 2

Views: 1232

Answers (2)

Sagar Kadam
Sagar Kadam

Reputation: 485

Simplest technique is nested Foreach look ... Like

foreach($arrD as $key => $arrInternal){

    foreach($arrInternal as $keyIn => $Data){

          //Perform your operation here
    }

}

Upvotes: 4

xdazz
xdazz

Reputation: 160833

foreach ($d["T"] as &$var) {
  $var['Pay'] = number_format($var['Pay'], 2, '.', '');
}

Upvotes: 3

Related Questions