<?php
$array = [
0 => [
"label" => "Radiator",
"details" => [[
"label" => "Condition",
"value" => "New",
],
[
"label" => "Type",
"value" => "Wall",
]],
],
1 => [
"label" => "Airco",
"details" => [[
"label" => "Condition",
"value" => "New",
],
[
"label" => "Type",
"value" => "",
]],
],
2 => [
"label" => "Refrigerator",
"details" => [[
"label" => "Condition",
"value" => "Bad",
],
[
"label" => "Type",
"value" => "Wall",
]],
],
];
foreach($array as &$row){
foreach($row['details'] as $key => $record){
if(strlen($record['value']) == 0){
unset($row['details'][$key]);
}
}
}
print_r($array);
- Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.14
- Array
(
[0] => Array
(
[label] => Radiator
[details] => Array
(
[0] => Array
(
[label] => Condition
[value] => New
)
[1] => Array
(
[label] => Type
[value] => Wall
)
)
)
[1] => Array
(
[label] => Airco
[details] => Array
(
[0] => Array
(
[label] => Condition
[value] => New
)
)
)
[2] => Array
(
[label] => Refrigerator
[details] => Array
(
[0] => Array
(
[label] => Condition
[value] => Bad
)
[1] => Array
(
[label] => Type
[value] => Wall
)
)
)
)
preferences:
58.82 ms | 410 KiB | 5 Q