$new_arr = [];
foreach ($arr['description'] as $desc) {
$tmp = $arr;
$tmp['description'] = $desc;
$new_arr[] = $tmp;
}
function mergeCount($arr) {
$keys = [];
foreach($arr as $item) {
$id = $item['id'];
$user = $item['user'];
if( isset( $keys[ $user])) {
$keys[ $user]['count']++;
} else {
$keys[$user] = [
'id' => $id,
'count' => 1
];
}
}
$result = [];
foreach($keys as $user=>$item) {
$result[] = [
'id' => $item['count'] > 1 ? $item['count'] : $item['id'],
'user' => $user
];
}
return $result;
}
$data = [
['id'=>367, 'user'=>'text'],
['id'=>370, 'user'=>'text'],
['id'=>432, 'user'=>'text1'],
['id'=>234, 'user'=>'text33'],
['id'=>264, 'user'=>'text33'],
];
$a = mergeCount($data);
print_r($a);
Array
(
[0] => Array
(
[id] => 2
[user] => text
)
[1] => Array
(
[id] => 432
[user] => text1
)
[2] => Array
(
[id] => 2
[user] => text33
)
)
$sweet = array('a' => 'apple', 'b' => 'banana');
$fruits = array('sweet' => $sweet, 'sour' => 'lemon');
function test_print($item, $key)
{
echo "$key holds $item\n";
}
array_walk_recursive($fruits, 'test_print');
// рекуксивный обход массива $array и удаление элемента с КЛЮЧЕМ(ключами) $value
function removeArrElemByKey( &$array, $value ){
if(count($array) > 1)
foreach( $array as $key => $val ){
if( is_array($val) ){
removeArrElemByKey($array[$key], $value);
} elseif( $val===$value ){
unset($array[$key]);
}
}
}