【问题标题】:Unwrap array inside another array PHP在另一个数组 PHP 中展开数组
【发布时间】:2021-09-01 08:37:48
【问题描述】:

我得到一个与逗号分隔的字符串,我试图将它们拆分成一个数组,这很有效。唯一的问题是有一个外部数组包装了我要使用的数组。所以我不想在将数组传递给函数时使用$excludes[0]。有谁知道我可以用来解开$excludes[0]中的数组的函数

$excludes = [];
 
Array ( [0] => Array ( 
[0] => company_logo,
[1] => social_links,
[2] => rss_link,
[3] => telephone ) ) 

我的预期结果如下。

 
Array ( 
 [0] => company_logo,
 [1] => social_links,
 [2] => rss_link,
 [3] => telephone 
)

【问题讨论】:

  • $excludes = $excludes[0]; ...?!?

标签: php arrays laravel


【解决方案1】:

你可以简单地做:

第一个选项:

print_r(array_shift($excludes));

第二个选项:

$new_array = $excludes[0];
print_r($new_array);

希望这会奏效

【讨论】:

  • 我想我需要选项 1,我已经了解了选项 2。谢谢,它可以了,我只需要阅读函数文档。
  • @LehlohonoloMotsoeneng 欢迎。
  • @LehlohonoloMotsoeneng 如果我的回答对您有帮助,请接受我的回答。
【解决方案2】:

检查一下

 $excludes = Array ( 0 => Array ( 
                    0 => 'company_logo',
                    1 => 'social_links',
                    2 => 'rss_link',
                    3 => 'telephone' ) ) ;

            
                    $excludes=$excludes[0];
                    print_r($excludes);die();

【讨论】:

  • 这是我目前的解决方案,但我觉得这是一个 hack,所以希望可能有一个内置函数来处理它。不过谢谢!
猜你喜欢
  • 2014-05-01
  • 2021-03-31
  • 1970-01-01
  • 2017-12-24
  • 2015-08-07
  • 2012-07-21
  • 1970-01-01
  • 2015-09-19
  • 2013-08-21
相关资源
最近更新 更多