私は多次元の2つの配列を使います。PHP: - 多次元配列
すべてのremove要素で同じ値を削除する必要がありますが、関数を使用する必要はありません。
多次元配列の下のコードを参照してください。
<?php
$a=array("0" => "test_3","1" => "test_4");
$b=array('test'=>array("label"=>"TEST","value"=>array(
"0"=>array("value"=>"test_1","label"=>"[test] Services_1"),
"1"=>array("value"=>"test_2","label"=>"[test] Services_2"),
"2"=>array("value"=>"test_3","label"=>"[test] Services_3"),
"3"=>array("value"=>"test_4","label"=>"[test] Services_4"),
)
),
'test1'=>array("label"=>"TEST","value"=>array(
"0"=>array("value"=>"test_11","label"=>"[test] Services_11"),
"1"=>array("value"=>"test_12","label"=>"[test] Services_12"),
"2"=>array("value"=>"test_13","label"=>"[test] Services_13"),
"3"=>array("value"=>"test_14","label"=>"[test] Services_14"),
)
)
);
echo "<pre>";
print_r($a);
print_r($b);
foreach($a as $val)
{
$search =$val;
$result = array_map(function ($value) use ($search) {
//print_r($value);
if(($key = array_search($search, $value['value'])) !== false) {
unset($value['value'][$key]);
}
}, $b);
print_r($result);
}
echo "</pre>";
?>
OUTのPUT: -
Array
(
[0] => test_3
[1] => test_4
)
Array
(
[test] => Array
(
[label] => TEST
[value] => Array
(
[0] => Array
(
[value] => test_1
[label] => [test] Services_1
)
[1] => Array
(
[value] => test_2
[label] => [test] Services_2
)
[2] => Array
(
[value] => test_3
[label] => [test] Services_3
)
[3] => Array
(
[value] => test_4
[label] => [test] Services_4
)
)
)
[test1] => Array
(
[label] => TEST
[value] => Array
(
[0] => Array
(
[value] => test_11
[label] => [test] Services_11
)
[1] => Array
(
[value] => test_12
[label] => [test] Services_12
)
[2] => Array
(
[value] => test_13
[label] => [test] Services_13
)
[3] => Array
(
[value] => test_14
[label] => [test] Services_14
)
)
)
)
そして、ここでは、私は次のようにします。
Array
(
[test] => Array
(
[label] => TEST
[value] => Array
(
[0] => Array
(
[value] => test_1
[label] => [test] Services_1
)
[1] => Array
(
[value] => test_2
[label] => [test] Services_2
)
)
)
[test1] => Array
(
[label] => TEST
[value] => Array
(
[0] => Array
(
[value] => test_11
[label] => [test] Services_11
)
[1] => Array
(
[value] => test_12
[label] => [test] Services_12
)
[2] => Array
(
[value] => test_13
[label] => [test] Services_13
)
[3] => Array
(
[value] => test_14
[label] => [test] Services_14
)
)
)
)
お願いします。
あなたは問題を解決するためにあなたの試行錯誤を行うコードはありますか? – rokas
はい、私はそれのために多くのコードを試していますが、私は完璧な結果@rokasを得ることができません。 –
ちょうどforeach(たぶん2つ)を使用して配列内のifを使用して設定を解除します – Ghost