Want more features on Pastebin? Sign Up, it's FREE!
Guest

PHP how do i write a multi dimmensional array into file

By: a guest on Feb 22nd, 2012  |  syntax: None  |  size: 1.31 KB  |  views: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. $board = array(
  2.          array(0,0,0,0,0,0,0,0,0),
  3.          array(0,0,0,0,0,0,0,0,0),
  4.          array(0,0,0,0,0,0,0,0,0),
  5.          array(0,0,0,0,0,0,0,0,0),
  6.          array(0,0,0,0,0,0,0,0,0),
  7.          array(0,0,0,0,0,0,0,0,0),
  8.          array(0,0,0,0,0,0,0,0,0),
  9.          array(0,0,0,0,0,0,0,0,0),
  10.          array(0,0,0,0,0,0,0,0,0)
  11.    );
  12.        
  13. $row = 0;
  14.     print "<form>";
  15.     print "<table border = 1>";
  16.     while ($row < 8){ // Counts to 8. (from 0...7 = 8 times. 0 ... 8 = 9 times)
  17.        print "<tr>";
  18.        $row++;
  19.        $col = 0; // reset column to 0 each time printing one row.
  20.  
  21.        while ($col < 8){
  22.         print "<td>";
  23.         if($Board[$row][$col] == 0)
  24.         {
  25.             $value=$row.$col;
  26.             print "<input type="checkbox" name="box[]" value="$value">";
  27.             // Add  before " otherwise it will treat as the end of the quote.
  28.  
  29.         }
  30.         print "</td>";
  31.         $col++;
  32.  
  33.        }
  34.  
  35.        print "</tr>";
  36.  
  37.     }
  38.     print "</table>";
  39.     print "</form>";
  40.        
  41. file_put_contents($f, serialize($board));
  42.        
  43. $board = unserialize(file_get_contents($f));
  44.        
  45. #dump:
  46. file_put_contents('file_name', serialize($board));
  47. #restore:
  48. $board=unserialize(file_get_contents('file_name'));
  49.        
  50. #dump:
  51. file_put_contents('file_name', json_encode($board));
  52. #restore:
  53. $board=json_decode(file_get_contents('file_name'));
clone this paste RAW Paste Data