0

我有这个

    <?php 
    if(isset($_GET['datos'])){
        $xd = $_GET['datos'];

       $datosCompletos = explode(',', $xd);
       $longArreglo = count($datosCompletos);

       for ($i=0; $i < $longArreglo; $i++) { 
            $arregloInformacion = explode('|', $datosCompletos[$i]);

        $longInformacion = count($arregloInformacion);
        $dato = "dato".$i; 
        for ($u=0; $u < $longInformacion; $u++) {
            $dato[$u] = $arregloInformacion[$u];
            echo $dato[$u];

        }
   }
}
?>

这是我发送的数据 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

我需要进去

$dato0[0] = Sria.plan
$dato0[1] = Fnzas
$dato0[2] = 139
$dato0[3] = ... //etc

$dato1[0] = Sria.plan.fnzas
$dato1[1] = Tesoreria
$dato1[2] = 1538
$dato1[3] = ... //etc

$dato2[0] = Sria.plan.fnzas
$dato2[1] = Tesoreria
$dato2[2] = 1500
$dato2[3] = ... //etc

但是通过这段代码,我得到了这个:SF1L220TT12H362167188ST1R520TT11M122122322ST1M220BH12M482189111

为什么?!

4

6 回答 6

1

要使用变量变量,您需要加倍$

$$dato[$u] = $arregloInformacion[$u];

但是你为什么要用不同的"dato".$i变量来做呢?为什么不使用多维数组:

$dato[$i] = $arregloInformacion;
于 2013-11-14T06:16:11.377 回答
0

问题是这段代码:

$dato = "dato".$i; 
for ($u=0; $u < $longInformacion; $u++) {
    $dato[$u] = $arregloInformacion[$u];
    echo $dato[$u];
}

您初始化$dato为字符串。然后,当您尝试引用 时,PHP 认为您的意思是偏移量处$dato[$u]的字符串 () 的字符。您得到的输出是每个数据点的第一个字母,因此 Sria.plan、Fnzas、139 等变为 SF1...$dato$u

你想这样做(未经测试):

$arrayName = "dato".$i;
$$arrayName = array();
for ($u=0; $u < $longInformacion; $u++) {
    $$arrayName[$u] = $arregloInformacion[$u];
    echo $$arrayName[$u];
}
于 2013-11-14T06:18:16.957 回答
0
<?php 
if(isset($_GET['datos'])){
  $outerArr = explode(',', $_GET['datos']);
  foreach ($outerArr as $items) {
    $data = explode('|', $items);
    $i = 0;
    foreach ($data as $dato) {
      $datos[$i] = $dato;
      echo $datos[$i];
      $i++;
    }
  }
}
?>

没跑。

于 2013-11-14T06:23:28.357 回答
0

只需用这个 100% 测试的代码替换您的代码

<?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 < $longArreglo; $i++) {
    $arregloInformacion = explode('|', $datosCompletos[$i]);
    $longInformacion = count($arregloInformacion);
    $dato = "dato" . $i;
    for ($u = 0; $u < $longInformacion; $u++) {
        $final_array[$dato][$u] = $arregloInformacion[$u];
    }
}
echo "<pre>";
print_r($final_array);
?>

输出将是

Array
(
    [dato0] => Array
        (
            [0] => Sria.plan
            [1] => Fnzas
            [2] => 139
            [3] => Lopez%20Portillo%20Alcantara%20Jorge%20Ernesto
            [4] => 29
            [5] => 2013-05-01
            [6] => 0000188B
            [7] => T
            [8] => Titular
            [9] => 1984-03-19
            [10] => 2011-07-16
            [11] => H
            [12] => 341.45
            [13] => 6305
            [14] => 276
            [15] => 153
            [16] => 673.4
            [17] => 7407.4
            [18] => 1185.18
            [19] => 8592.58
            [20] => 8674.75
        )

    [dato1] => Array
        (
            [0] => Sria.plan.fnzas
            [1] => Tesoreria
            [2] => 1538
            [3] => Rodriguez%20Guzman%20Noemi
            [4] => 58
            [5] => 2011-05-01
            [6] => 0000188A
            [7] => T
            [8] => Titular
            [9] => 1998-12-16
            [10] => 1994-07-09
            [11] => M
            [12] => 1083.78
            [13] => 20841
            [14] => 276
            [15] => 153
            [16] => 2127
            [17] => 23397
            [18] => 3743.52
            [19] => 27140.5
            [20] => 27222.7
        )

    [dato2] => Array
        (
            [0] => Sria.plan.fnzas
            [1] => Tesoreria
            [2] => 1500
            [3] => Martinez%20Rodriguez%20Edith
            [4] => 23
            [5] => 2013-05-01
            [6] => 0000188C
            [7] => B
            [8] => Hija
            [9] => 1989-07-25
            [10] => 2006-04-16
            [11] => M
            [12] => 438.62
            [13] => 8208
            [14] => 276
            [15] => 153
            [16] => 863.7
            [17] => 9500.7
            [18] => 1520.11
            [19] => 11020.8
            [20] => 11103
        )

)
于 2013-11-14T06:30:43.177 回答
0

请试试这个它会工作

$_GET['datos'] ='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 |名义|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';

if(isset($_GET['datos'])){
    $xd = $_GET['datos'];

   $datosCompletos = explode(',', $xd);
   foreach($datosCompletos as $key=>$value ){
        $datosCompletos = explode('|', $value);
        foreach($datosCompletos as $newkey=>$newvalue ){
            $datavalue[$key][$newkey] =  $newvalue;
        }
   }

echo "<pre>";
print_r($datavalue);
于 2013-11-14T06:41:16.390 回答
0

这有效

  <?php
  $_GET['datos']="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";

  if (isset($_GET['datos']))
  {
     $xd = $_GET['datos'];
     $datosCompletos = explode(',', $xd);
     $longArreglo    = count($datosCompletos);

     for ($i = 0; $i < $longArreglo; $i++)
     {
        $arregloInformacion = explode('|', $datosCompletos[$i]);

        $longInformacion = count($arregloInformacion);
        $dato            = "dato" . $i;
        for ($u = 0; $u < $longInformacion; $u++)
        {
           $tmp=$$dato;
           $tmp[$u] = $arregloInformacion[$u];
           $$dato=$tmp;
        }
     }
        var_dump($dato0[0]);
        var_dump($dato0[1]);
        var_dump($dato0[2]);

        var_dump($dato1[0]);
        var_dump($dato1[1]);
        var_dump($dato1[2]);
  }
  ?>
于 2013-11-14T06:43:34.697 回答