0

I have array

$Old = [_1526906780329_329] => Array (
    [frlabel] => aa
    [enlabel] => AA
    )
[_1526906783640_640] => Array (
    [frlabel] => bb
    [enlabel] => BB
    )

I want $old array to convert it in single array key value format like

array('AA' => 'aa','BB' => 'bb');
2
  • 1
    What code you used to do the convert and where you are getting struck? Commented May 21, 2018 at 13:02
  • @Sam Swift 웃 none of that answer solved my question which you suggest,thanks Commented May 22, 2018 at 4:46

3 Answers 3

3
$Old = [
    '_1526906780329_329' => [
        'frlabel' => 'aa',
        'enlabel' => 'AA',
    ],
    '_1526906783640_640' => [
        'frlabel' => 'bb',
        'enlabel' => 'BB',
    ],
];

$newArray = array_column($Old, 'frlabel', 'enlabel');
print_r($newArray);

Output:

Array
(
    [AA] => aa
    [BB] => bb
)
Sign up to request clarification or add additional context in comments.

Comments

1
<?php 


    $final = array();
    $Old[_1526906780329_329] = Array (
        'frlabel' => 'aa',
        'enlabel' => 'AA',
        );

    $Old[_1526906783640_640] = Array (
        'frlabel' => 'bb',
        'enlabel' => 'BB',
        );

    foreach ($Old as $key => $value) {
        $final[$value['enlabel']] = $value['frlabel'];
    }
    echo "<pre>";print_r($final);

Comments

0

Assuming this is data specific...

$array1 = array();
$array1['frlabel'] = 'aa';
$array1['enlabel'] = 'AA';

$array2 = ['frlabel' => 'bb', 'enlabel' => 'BB'];

$old = array();
$old[] = $array1;
$old[] = $array2;
$result = array();

foreach($old as $tmp){
    $result[$tmp['enlabel']] = $tmp['frlabel'];
}

var_dump($result);

Output:

array(2) {
    ["AA"]=>
    string(2) "aa"
    ["BB"]=>
    string(2) "bb"
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.