Multidimensional Array ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pankajit09
    Contributor
    • Dec 2006
    • 296

    Multidimensional Array ?

    Please correct the multidimensiona l array "a" below -->


    Code:
    <html>
    <body>
    
    <?php
    
    $input = explode(" ", $_POST['input']);
    
    $row = $input[0];
    $col = $input[1];
    
    $k=2;
    $a = array();
    
    for($i=0; $i<$row; $i++) {
    for($j=0; $i<$col; $i++) {
    	$a[$i][$j] = $input[$k];
    	$k++;
    }
    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by pankajit09
    Please correct the multidimensiona l array "a" below -->


    Code:
    <html>
    <body>
     
    <?php
     
    $input = explode(" ", $_POST['input']);
     
    $row = $input[0];
    $col = $input[1];
     
    $k=2;
    $a = array();
     
    for($i=0; $i<$row; $i++) {
    for($j=0; $i<$col; $i++) {
    	$a[$i][$j] = $input[$k];
    	$k++;
    }
    }
    What's wrong with it?

    Comment

    • pankajit09
      Contributor
      • Dec 2006
      • 296

      #3
      Originally posted by r035198x
      What's wrong with it?

      Will the multidimensiona l array "a" be globally available ?

      global $a ;

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        I don't see why not. What is the problem

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          What kind of data does $_Post['Input'] contain?

          P.S. Your second for loop adds to the index of the first one.

          Comment

          Working...