Php 如何拆分数组并显示特定元素

Php 如何拆分数组并显示特定元素,php,split,explode,Php,Split,Explode,下面是我的数组输出 [0] => Array [OrderDetails] => Array ( [Options] => [Nicotine Level:12mg Nicotine][Sampler Item 1:Krankberry][Sampler Item 2:Unicorn Blood][Sampler Item 3:WaterFelons] ) ) 我只想显示选项字段中的尼古丁水平,选项可能会有所不同,请帮助我。我有很多选项 我使用了下面的代码 $expl

下面是我的数组输出

 [0] => Array
[OrderDetails] => Array
(

  [Options] => [Nicotine Level:12mg Nicotine][Sampler Item 1:Krankberry][Sampler Item 2:Unicorn Blood][Sampler Item 3:WaterFelons]
)
)
我只想显示选项字段中的尼古丁水平,选项可能会有所不同,请帮助我。我有很多选项

我使用了下面的代码

$explode_var = explode('[','[Nicotine Level:12mg Nicotine][Sampler Item 1:Krankberry][Sampler Item 2:Unicorn Blood][Sampler Item 3:WaterFelons]');

echo '<pre>';
print_r($explode_var);
echo '</pre>';
$explode\u var=explode(“[”,“[尼古丁含量:12mg尼古丁][采样器项目1:Krankberry][采样器项目2:独角兽血液][采样器项目3:Waterelons]);
回声';
打印($explode\u var);
回声';

这是一种方法阅读代码上的注释:


<?php
$data = array(array('OrderDetails' => array('Options' => '[Nicotine Level:12mg Nicotine][Sampler Item 1:Krankberry][Sampler Item 2:Unicorn Blood][Sampler Item 3:WaterFelons]')));

$options = $data[0]['OrderDetails']['Options'];
$options = str_replace(']', '', $options);
$old_var = array_filter(explode('[',$options));
$result = array();
foreach ($old_var as $items)
{
    $item = explode(':', $items);
    $result[$item[0]] = $item[1];
}

foreach ($result as $key=>$value)
{
    echo $key, " => ", $value, "<br/>\n";
}