【问题标题】:Remove indexing from an array [duplicate]从数组中删除索引[重复]
【发布时间】:2015-07-27 09:49:11
【问题描述】:

我有以下数组:

array(3) { 
    [0]=> array(1) { ["theme_loader_plugin"]=> string(4) "_run" } 
    [1]=> array(1) { ["user_plugin"]=> string(4) "_run" } 
    [2]=> array(1) { ["sessions_plugin"]=> string(4) "_run" } 
} 

有没有办法使用预定义的 php 函数删除索引,而是像这样格式化它:

array(3) { 
    ["theme_loader_plugin"]=> string(4) "_run",
    ["user_plugin"]=> string(4) "_run",
    ["sessions_plugin"]=> string(4) "_run"
} 

【问题讨论】:

  • 按照@Rizier123 的建议通过array_keys 直接获取所有

标签: php


【解决方案1】:

遍历数组并将它们合并到新数组。希望它会有所帮助-

$arr = array( 
   array("theme_loader_plugin"=>  "_run" ) ,
   array("user_plugin"=> "_run" ) ,
   array("sessions_plugin"=> "_run" )
) ;

$new=  array();
foreach($arr as $val) {
  $new = array_merge($new, $val);
}

输出

array(3) {
  ["theme_loader_plugin"]=>
  string(4) "_run"
  ["user_plugin"]=>
  string(4) "_run"
  ["sessions_plugin"]=>
  string(4) "_run"
}

【讨论】:

  • thnks,但我正在寻找一个预定义的 php 函数。我会接受它。
  • 你必须为此做一些技巧。
猜你喜欢
  • 2012-02-24
  • 2014-11-07
  • 2012-02-12
  • 1970-01-01
  • 2021-11-06
  • 2018-05-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多