title: PHP array stringify
body: <p>In a lyrics application I'm coding, I'm using an array to print an artists table. The artists array looks like this:</p>
  
  <pre><code>$artists = [
      [ "Avril Lavigne"               ],
      [ "3 Doors Down"                ],
      [ "Celine Dion"                 ],
      [ "Evanescence"                 ],
      [ "Shania Twain"                ],
      [ "Green Day"                   ],
      //...
  ];
  </code></pre>
  
  <p>Before printing it, I do some modification to the array. I have a folder for each artist that contains the lyrics files. I add the folder names to the <code>$artists</code> array for later use:</p>
  
  <pre><code>$folder_fix = [
      [" ",   "_" ],
      [".",   ""  ],
      ["&amp;",   "n" ],
  ];
  
  for ($i = 0; $i &lt; count($artists); $i++) {
      $folder_name = strtolower($artists[$i][0]);
      for ($k = 0; $k &lt; count($folder_fix); $k++) {
          $folder_name = str_replace($folder_fix[$k][0], $folder_fix[$k][1], $folder_name);
      }
      array_push($artists[$i], $folder_name);
  }
  </code></pre>
  
  <p>Later, I add the album and track count for each artist to the array:</p>
  
  <pre><code>$lyrics_base = "lyrics/";
  for ($i = 0; $i &lt; count($artists); $i++) {
      $albums_path    = $lyrics_base . $artists[$i][1] . "/*";
      $tracks_path    = $lyrics_base . $artists[$i][1] . "/*/*";
      $albums         = count(glob($albums_path));
      $tracks         = count(glob($tracks_path));
      array_push($artists[$i], $albums);
      array_push($artists[$i], $tracks);
  }
  </code></pre>
  
  <p>The end result of the array looks like this:</p>
  
  <pre><code>$artists = [
      [ "Avril Lavigne",  "avril_lavigne",    5,  61  ],
      [ "3 Doors Down",   "3_doors_down",     5,  13  ],
      [ "Celine Dion",    "celine_dion",      7,  22  ],
      [ "Evanescence",    "evanescence",      4,  10  ],
      [ "Shania Twain",   "shania_twain",     3,  12  ],
      [ "Green Day",      "green_day",        8,  26  ],
      //...
  ];
  </code></pre>
  
  <p>Now, my problem is that this process happens every time I visit the page. The 2nd, 3rd, and the 4th columns are created again and again. I think this is redundant.</p>
  
  <p>I want to save the end result of the array and use it on the page. If this was JavaScript I'd use <code>JSON.stringify()</code>, but in PHP I don't know how to get the end result of the array. <code>print_r()</code> doesn't do the job, because it prints it like this:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [0] =&gt; Avril Lavigne
              [1] =&gt; avril_lavigne
              [2] =&gt; 5
              [3] =&gt; 61
          )
  
      [1] =&gt; Array
          (
              [0] =&gt; 3 Doors Down
              [1] =&gt; 3_doors_down
              [2] =&gt; 5
              [3] =&gt; 13
          )
  ...
  </code></pre>
  
  <p>I want it like this:</p>
  
  <pre><code>[
      [
          "Avril Lavigne",
          "avril_lavigne",
          5,
          61
      ],
      [
          "3 Doors Down",
          "3_doors_down",
          5,
          13
      ],
      //...
  ]
  </code></pre>
  
  <p>Is there a way to print the array the <code>JSON.stringify()</code> way?</p>