Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6088307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:58:11+00:00 2026-05-23T11:58:11+00:00

I have two arrays: Array ( [0] => Array ( [id] => 1 [type]

  • 0

I have two arrays:

Array
(
[0] => Array
    (
        [id] => 1
        [type] => field
        [remote_name] => Title
        [my_name] => title
        [default_value] => http%3A%2F%2Ftest.com
    )

[1] => Array
    (
        [id] => 2
        [type] => field
        [remote_name] => BookType
        [my_name] => book-type
        [default_value] => 
    )

[2] => Array
    (
        [id] => 3
        [type] => value
        [remote_name] => dvd-disc
        [my_name] => dvd
        [default_value] => 
    )
)


Array
(
[title] => Test
[book-type] => dvd
)

I need to take each key in the second array, match it with the my_name value in the first array and replace it with the corresponding remote_name value of the first array while preserving the value of the second array.

There’s got to be some carrayzy function to help!

EDIT: There will also be a few cases that the value of the second array will need to be replaced by the value of the first array’s remote_name where the value of the second array matches the value of the first array’s my_name. How can I achieve this?

EG: book-type => dvd should turn into BookType => dvd-disc

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:58:11+00:00Added an answer on May 23, 2026 at 11:58 am

    Like so?:

    $first = array(
        array(
            'id' => 1,
            'type' => 'field',
            'remote_name' => 'Title',
            'my_name' => 'title',
            'default_value' => 'http%3A%2F%2Ftest.com',
        ),
        array(
            'id' => 2,
            'type' => 'field',
            'remote_name' => 'BookType',
            'my_name' => 'book-type',
            'default_value' => '',
        ),
        array(
            'id' => 3,
            'type' => 'value',
            'remote_name' => 'dvd-disc',
            'my_name' => 'dvd',
            'default_value' => '',
        ),
    );
    
    $second = array(
        'title' => 'Test',
        'book-type' => 'dvd',
    );
    
    $map = array('fields' => array(), 'values' => array());
    foreach ($first as $entry) {
        switch ($entry['type']) {
            case 'field':
                $map['fields'][$entry['my_name']] = $entry['remote_name'];
                break;
    
            case 'value':
                $map['values'][$entry['my_name']] = $entry['remote_name'];
                break;
        }
    }
    
    $new = array();
    foreach ($second as $key => $val) {
        $new[isset($map['fields'][$key]) ? $map['fields'][$key] : $key] = isset($map['values'][$val]) ? $map['values'][$val] : $val;
    }
    
    print_r($new);
    

    Output:

    Array
    (
        [Title] => Test
        [BookType] => dvd-disc
    )
    

    Explanation:

    The first loop collects the my_name/remote_name pairs for fields and values and makes them more accessible.
    Like so:

    Array
    (
        [fields] => Array
            (
                [title] => Title
                [book-type] => BookType
            )
    
        [values] => Array
            (
                [dvd] => dvd-disc
            )
    
    )
    

    The second loop will traverse $second and use the key/value pairs therein to populate $new. But while doing so will check for key/value duplicates in $map.

    Keys or values not found in the map will be used as is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrays. In first array I have Type and Zone field names.
I have two arrays: Array ( [2005] => 0 [2006] => 0 [2007] =>
Consider I have two arrays: $friends = Array('foo', 'bar', 'alpha'); $attendees = Array('foo', 'bar');
I have two arrays in PHP. The first array ($author_array) is comprised of user_ids
I have two arrays of animals (for example). $array = array( array( 'id' =>
I'm using php with smarty. In php I have two arrays: $code = Array
Let's say I have two arrays: int ArrayA[] = {5, 17, 150, 230, 285};
I have two JavaScript arrays: var array1 = [Vijendra,Singh]; var array2 = [Singh, Shakya];
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two arrays. One contains id=>count and the other contains id=>name . I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.