php数组将所有元素合并为一个并删除引号

时间:2014-02-23 02:39:07

标签: php arrays merge

我需要从文本中解析一些数据,因此我将其复制/粘贴到数组中并像这样使用它:

   $array = array("_alpha","_beta","_gama","_delta","_epsilon");
   foreach ($array as $key => $value) {
      {use the value in my script bellow....}
   }

数据来自一个脚本,该脚本在文件顶部有私有声明,因此很容易复制/粘贴它。

$private = ["_alpha","_beta","_gama","_delta","_epsilon"];

现在我必须解析许多文件,所以我试图将尽可能多的$ array数据收集到一个数组中,所以我可以使用相同的函数解析它...好吧我能想出来的最好是这个:

Array
(
    [0] => "_alpha","_delta","_beta","_epsilon","_delta","_kapa",
    [1] => "_beta","_alpha","_delta","_kapa","_lamda","_epsilon","_array","_alpha"
    [2] => "_epsilon","_array","_alpha","_theta","_omega"
    [3] => "_alpha"
    [4] => "_kapa","_lamda","_epsilon"
    [5] => "_beta","_epsilon","_delta","_kapa","_lamda"
    [6] => "_omega","_omega","_delta"
        ....
        ....
}

每一行代表文件的标题。 请注意值周围的引号 ... 我怎样才能使上面看起来像这样:

Array
(
    [0] => _alpha
    [1] => _beta
    [2] => _gama
    [3] => _delta
    [4] => _epsilon
    ...
    ...
    ..
)

每个值本身,没有引号或逗号等......只是一个普通的值。

我也可以用这种格式提取数据..但我认为这样做更难:

Array
(
    [0] => Array
                    (
                        [0] => "_alpha"
                        [1] => "_beta"
                        [2] => "_gama"
                        [3] => "_delta"
                        [4] => "_epsilon"
                        ...
                        ...
                        ..
                    )

    [1] => Array
                    (
                        [0] => "_alpha"
                        [1] => "_beta"
                        [2] => "_gama"
                        [3] => "_delta"
                        [4] => "_epsilon"
                        [5] => "_epsilon"
                        ...
                        ..
                    )
  ...... etc etc ......
  [10] => Array
                    (
                        [0] => "_alpha"
                        [1] => "_delta"
                        [2] => "_omega"
                    )
}

_Thanks

1 个答案:

答案 0 :(得分:0)

$private = ["_alpha","_beta","_gama","_delta","_epsilon"];
print_r($private);
Array
(
    [0] => _alpha
    [1] => _beta
    [2] => _gama
    [3] => _delta
    [4] => _epsilon
)

我不知道这个问题是什么 但是当我使用你的代码时,一切正常