Home:ALL Converter>Copying specific keys and values of a PHP multidimensional array into another array

Copying specific keys and values of a PHP multidimensional array into another array

Ask Time:2018-06-08T22:10:46         Author:Phoenix

Json Formatter

I have a multidimensional array like this:

Array
(
    [0] => Array
        (
            [id] => 1
            [name] => mail_failures_only
            [value] => 0
        )

    [1] => Array
        (
            [id] => 2
            [name] => default_service_ttl
            [value] => 60
        )

    [2] => Array
        (
            [id] => 3
            [name] => version
            [value] => 5.0.0.0
        )

    [3] => Array
        (
            [id] => 4
            [name] => process_all_jobs
            [value] => 1
        )
)

I want each value of "name" and each value of "value" to be converted to an associative array like this:

process_all_jobs =>1

How do a construct loop for this?

I tried something like this:

$system_config_array = array();
        if (is_array($configList)) {
            $keys = array_keys($configList);
            for($i = 0; $i < count($configList); $i++) {
                foreach($configList[$keys[$i]] as $key => $value) {
                    echo $key . " : " . $value . "<br>";
                    if($key!='id')
                        $system_config_array[$value] = '';
                }
            }
       }

where $configList is the initial array.

Author:Phoenix,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50762539/copying-specific-keys-and-values-of-a-php-multidimensional-array-into-another-ar
Pradeep :

Hope this will help you :\n\n$base = 'your array';\nforeach ($base as $key => $value) {\n $data[$value['name']] = $value['value'];\n}\nprint_r($data);\n\n\nhttps://eval.in/1017632",
2018-06-08T14:18:40
yy