Q:

How to find same name in array of array and combine their values in PHP?

I have this type array structure.
Array
(
    [0] => Array
        (
            [name] => Name
            [value] => Ram
        )

    [1] => Array
        (
            [name] => Gender
            [value] => Male
        )

    [2] => Array
        (
            [name] => Age
            [value] => 25
        )

    [3] => Array
        (
            [name] => Color
            [value] => Red
        )

    [4] => Array
        (
            [name] => Color
            [value] => Yellow
        )

    [5] => Array
        (
            [name] => Game
            [value] => Cricket
        )

    [6] => Array
        (
            [name] => Game
            [value] => Football
        )

    .
    .
    .
)

How can I find same names containing in whole array and combine their values? In above, Color and Game name is same, so I need Color and Game values in array instead. Note that there may be other names being similar not only Color and Game.
Array
(
    [0] => Array
        (
            [name] => Name
            [value] => Ram
        )

    [1] => Array
        (
            [name] => Gender
            [value] => Male
        )

    [2] => Array
        (
            [name] => Age
            [value] => 25
        )

    [3] => Array
        (
            [name] => Color
            [value] => array( 'Red', 'Yellow' )
        )

    [4] => Array
        (
            [name] => Game
            [value] => array( 'Cricket', 'Football' )
        )
    .
    .
    .
)

A:

Try below code. And check if that helps you.
Note: For future ref when you ask a question here please provide the code you did so far. In this question it seems like you didn't try to solve it.

<?php
    // example code

    $newarray = [
            [
                "name" => "Name",
                "value" => "Ram"
            ],
            [
                "name" => "Gender",
                "value" => "Male"
            ],
            [
                "name" => "Age",
                "value" => 25
            ],
            [
                "name" => "Color",
                "value" => "Red"
            ],
            [
                "name" => "Color",
                "value" => "Yellow"
            ],
        ];

//make an array of combined values using value of name as key of that array
    $keyArray = [];
    foreach($newarray as $k=>$v)
    {
        if(array_key_exists($v['name'],$keyArray))
        {
            $valueArray = [];
            if(is_array($keyArray[$v['name']]))
            {
                $valueArray = $keyArray[$v['name']];
                $valueArray[] = $v['value'];
                $keyArray[$v['name']] = $valueArray;
            }
            else
            {
                $valueArray[] = $keyArray[$v['name']];
                $valueArray[] = $v['value'];
                $keyArray[$v['name']] = $valueArray;
            }
        }
        else
        {
            $keyArray[$v['name']] = $v['value'];
        }
    }
//now loop through the key values and make key as name and value as value and push into a wrapper array
    $finalArray = [];
    foreach ($keyArray as $k=>$v)
    {
        $finalArray[] = [
                "name"=>$k,
                "value"=>$v
            ];
    }

    print_r($finalArray);

