 <p>Just replace your code With this one 100% tested </p> <pre><code>&lt;?php $xd = 'Sria.plan|Fnzas|139|Lopez%20Portillo%20Alcantara%20Jorge%20Ernesto|29|2013-05-01|0000188B|T|Titular|1984-03-19|2011-07-16|H|341.45|6305|276|153|673.4|7407.4|1185.18|8592.58|8674.75,Sria.plan.fnzas|Tesoreria|1538|Rodriguez%20Guzman%20Noemi|58|2011-05-01|0000188A|T|Titular|1998-12-16|1994-07-09|M|1083.78|20841|276|153|2127|23397|3743.52|27140.5|27222.7,Sria.plan.fnzas|Tesoreria|1500|Martinez%20Rodriguez%20Edith|23|2013-05-01|0000188C|B|Hija|1989-07-25|2006-04-16|M|438.62|8208|276|153|863.7|9500.7|1520.11|11020.8|11103'; $datosCompletos = explode(',', $xd); $longArreglo = count($datosCompletos); for ($i = 0; $i &lt; $longArreglo; $i++) { $arregloInformacion = explode('|', $datosCompletos[$i]); $longInformacion = count($arregloInformacion); $dato = "dato" . $i; for ($u = 0; $u &lt; $longInformacion; $u++) { $final_array[$dato][$u] = $arregloInformacion[$u]; } } echo "&lt;pre&gt;"; print_r($final_array); ?&gt; </code></pre> <p>Output will be </p> <pre><code>Array ( [dato0] =&gt; Array ( [0] =&gt; Sria.plan [1] =&gt; Fnzas [2] =&gt; 139 [3] =&gt; Lopez%20Portillo%20Alcantara%20Jorge%20Ernesto [4] =&gt; 29 [5] =&gt; 2013-05-01 [6] =&gt; 0000188B [7] =&gt; T [8] =&gt; Titular [9] =&gt; 1984-03-19 [10] =&gt; 2011-07-16 [11] =&gt; H [12] =&gt; 341.45 [13] =&gt; 6305 [14] =&gt; 276 [15] =&gt; 153 [16] =&gt; 673.4 [17] =&gt; 7407.4 [18] =&gt; 1185.18 [19] =&gt; 8592.58 [20] =&gt; 8674.75 ) [dato1] =&gt; Array ( [0] =&gt; Sria.plan.fnzas [1] =&gt; Tesoreria [2] =&gt; 1538 [3] =&gt; Rodriguez%20Guzman%20Noemi [4] =&gt; 58 [5] =&gt; 2011-05-01 [6] =&gt; 0000188A [7] =&gt; T [8] =&gt; Titular [9] =&gt; 1998-12-16 [10] =&gt; 1994-07-09 [11] =&gt; M [12] =&gt; 1083.78 [13] =&gt; 20841 [14] =&gt; 276 [15] =&gt; 153 [16] =&gt; 2127 [17] =&gt; 23397 [18] =&gt; 3743.52 [19] =&gt; 27140.5 [20] =&gt; 27222.7 ) [dato2] =&gt; Array ( [0] =&gt; Sria.plan.fnzas [1] =&gt; Tesoreria [2] =&gt; 1500 [3] =&gt; Martinez%20Rodriguez%20Edith [4] =&gt; 23 [5] =&gt; 2013-05-01 [6] =&gt; 0000188C [7] =&gt; B [8] =&gt; Hija [9] =&gt; 1989-07-25 [10] =&gt; 2006-04-16 [11] =&gt; M [12] =&gt; 438.62 [13] =&gt; 8208 [14] =&gt; 276 [15] =&gt; 153 [16] =&gt; 863.7 [17] =&gt; 9500.7 [18] =&gt; 1520.11 [19] =&gt; 11020.8 [20] =&gt; 11103 ) ) </code></pre>