0

I have 2 arrays

Array
(
    [0] => company
    [1] => companyid
)

Array
(
    [company] => shops
)

And I want the first array to look like this.

Array
    (
        [0] => shops
        [1] => companyid
    )

I've tried alot of built in array functions but I couldn't get a grip on them.

Anyone has an idea?

1 Answer 1

1

$data is your first array, $replacement is the second

foreach( $replacements as $key => $value ){
  $data_key = array_search( $key, $data );
  if( $data_key !== false ) $data[ $data_key ] = $value;
}
Sign up to request clarification or add additional context in comments.

2 Comments

It worked! but there has to be a small flip between the $data and $key so it looks likes this: $data[ array_search( $key, $data )] = $value;
Yes, I still haven't learned this: phpdevblog.net/uploads/files/haystack-needle.pdf

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.