title: Reducing a multi-dimensional array
body: <p>I have an array that carries a definite number of dimensions so I'm not really looking at something recursive (Unless maybe for maintainability sake in the future). It's a numeric array gotten from the database with each row holding another array. Each of those level 2 arrays contain strings like</p>
  
  <p><code>var1, var2 , var3</code></p>
  
  <p>And so on. Note the irregular appearance of commas in the string. So I intend to break the comma delimited string in the third level then log them in the final array but I get an error saying I am supplying an null array. So I want to know why it says the array is null and how I can make it recognise that as a valid array. My code goes below:</p>
  
  <pre><code>function fetch_each($arr) {
  $temp = array();
  
  for ($i = 0; $i &lt; count($arr); $i++) {
  for ($j = 0; $j &lt; count($arr[$i]); $j++) {
  array_reduce(preg_split("/[\s,]+/", $arr[$i][$j]), function($a, $b) {
  return array_push($temp, $a, $b);
  });
  }
  }
  return $temp;
  }
  </code></pre>
  
  <p>PS: Please don't mark as duplicate. I don't want to copy someone else's code but want to understand why this does not work. Thanks.</p>