In php, Number of rows and columns in a 2 D array? -


i have 2 dimensional array unknown number of elements.

$two_darray[row][column]; //there unknown integer values instead of row , column keywords

if write for loop follows, how can determine how many rows , columns in $two_darray. can please tell me if there library function in php can tell me value inside [????] [????]

for($row=0; $row<………; $row++) {     for($column =0; $column  <………; $ column ++)     {         echo $two_darray[$row][$column];     }     echo “\n end of 1 column \n”; } 

i need know value of rows , columns in order perform other calculations.

foreach ($two_darray $key => $row) {    foreach ($row $key2 => $val) {       ...    } } 

no need worry how many elements in each array, foreach() take care of you. if absolutely refuse use foreach, count() each array comes up.

$rows = count($two_d_array); ($row = 0; $row < $rows; $row++) {      $cols = count($two_darray[$row]);      for($col = 0; $col < $cols; $col++ ) {         ...      } } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -