谁能解释一下如何将下面的输入数组更改为输出数组,
输入Array
(
[24] => Array
(
[0] => Moto E
[1] => Moto G
)
[23] => Array
(
[0] => Moto G
)
[22] => Array
(
[0] => Nokia
[1] => Karbon
[2] => onida
[3] => micromax
[4] => L'oreal
[5] =>
)
[21] => Array
(
[0] => brand1
[1] => brand2
)
[20] => Array
(
[0] => Nokia
[1] => Apple
[2] => Sony
[3] => JVC
[4] => Samsung
)
)
Array
(
[24] => Array
(
[0] => Moto E
[1] => Moto G
)
[22] => Array
(
[0] => Nokia
[1] => Karbon
[2] => onida
[3] => micromax
[4] => L'oreal
[5] =>
)
[21] => Array
(
[0] => brand1
[1] => brand2
)
[20] => Array
(
[0] => Apple
[1] => Sony
[2] => JVC
[3] => Samsung
)
)
从上面的输入数组,如何删除重复的数组值,我的意思是'Moto G'和'Nokia'产品是重复的。因此,请给出将输入格式更改为输出格式的解决方案。
try this
$new_array = array();
$temp_array = array();
for($your_array as $key=>$arr_val)
{
$arr = array();
foreach($arr_val as $val)
{
if(!in_array($val, $temp_array))
{
$arr[] = $val;
$temp_array[] = $val;
}
}
if(sizeof($arr)>0)
{
$new_array[$key] = $arr;
}
}
演示工作