php - How to print an entire array when third dimension is constant -


how print entire array when 1 index constant.

for understanding purposes have made array

$actionf = array(     "enemyhlth" =>  array(array()),     "enemyblts" =>  array(array()) ); 

with input

3 2 1 1 2 3 3 2 1 1 2 3 3 2 1 1 2 3 

the array structure supposed store top 3 rows under 3d array 3rd dimension constant "enemy health" while bottom 3 in 3d array same 3rd dimension "enemy bullets". , both these 2 3d arrays stored in single array called actionf

now when try print it

for($level=0;$level<$n;$level++){       $actionf["enemyhlth"] = array ( $level =>  fscanf($_fp,"%d\t%d\t%d\n")                                     );             }  for($bullets = 0;$bullets<$m; $bullets++){       $actionf["enemyblts"] = array ( $bullets => fscanf($_fp,"%d\t%d\t%d\n")                                     );            } print_r($actionf); 

output

3 2 1 

i think printing last index of above i/p. how make 2d array when third dimension constant or there else missing?

i rewrote code , think works this:

first, input:

$actionf = array(         "enemyhlth" =>  array(),         "enemyblts" =>  array()         );  for($level=0;$level<$n;$level++){      $line = fgets($_fp);      $processed = explode(" ", $line);      if ($line != false) {         $actionf["enemyhlth"][$level] = $processed;     }  }  for($bullets = 0;$bullets<$m; $bullets++){        $line = fgets($_fp);      $processed = explode(" ", $line);      if ($line != false) {          $actionf["enemyblts"][$bullets] = $processed;                } } 

and here's output:

for($i=0;$i<$n;$i++){     for($j=0;$j<$m;$j++){         print $actionf["enemyhlth"][$i][$j];     }     print "\n"; } 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -