9

Array_combine with key to only one of table 1 and several values ​​of table 2

 3 years ago
source link: https://www.codesd.com/item/array-combine-with-key-to-only-one-of-table-1-and-several-values-of-table-2.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Array_combine with key to only one of table 1 and several values ​​of table 2

advertisements

I have 2 arrays:

array 1 I want it to be a keys(duplicate is ok) in array_combine:

Array
    (
        [0] => id
        [1] => user_id
        [2] => firstname
    )

And here's my array 2 that I wanted to be the values in array_combine:

Array
    (
        [0] => 363
        [1] => 363
        [2] => Omotayo
    )

Array
    (
        [0] => 167
        [1] => 167
        [2] => Shafraaz
    )

Now challenge is, I have 2 arrays the first one has only one array and the second array has 2 inside arrays. The first array that I wanted to be the keys(duplicate) in array_combine. My desire output like below:

    Array
    (
        [id] => 363
        [user_id] => 363
        [firstname] => Omotayo
    )
    Array
    (
        [id] => 167
        [user_id] => 167
        [firstname] => Shafraaz
    )

Just wonder is there way to achieve this task? Appreciated any advise!!

Thanks


Why not just run array_combine on each inner array of $array2?

$final = array();
foreach($array2 as $array) {
    $final[] = array_combine($array1, $array);
}

This'll leave $final as the expected array with proper key/value pairs.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK