Combining Two Unequal Arrays by Matching Keys

I have here two arrays. Array1 has a related value to array2. What I need is that I’m going to save both values at once. I used ‘array_combine’ function but my arrays are having unequal keys. Any help is greatly appreciated. Thank you.


$type = $_POST['dev_type'];
$sn = $_POST['dev_sn'];
Array
(
        [0] => 22
        [1] => 19
        [2] => 66
        [3] => 62
        [4] => 64
)
Array
(
        [0] => sn1
        [1] => sn2
        [2] => sn3
)

I’m not exactly sure what your question is. However, have you tried:

array_diff_key — Computes the difference of arrays using keys for comparison

Thank you for that.
here is what I really want.


Array 
( 
        [0] => 22 
        [1] => 19 =>sn1
        [2] => 66 
        [3] => 62 =>sn2 
        [4] => 64 =>sn3
)

Ok. Ill try that.


[0] => 22 
[1] => 19 =>sn1

I still do not understand what is required …

Is the end result supposed to end up as:


$array[0] = 22;
$array[1] = "19sn1";

OR


$array[0] = 22;
$array[1] = array(19, "sn1"); // an array of results

OR


$array[0] = 22;
$array[1] = array(19 => "sn1");  // a single array of results where key => "value"

OR
Something else?

I’m don’t know if your code will allow, but have you considered using the values from the first array as keys in the 2nd array

<?php

$arr1 = array ("22"=>"","19"=>"sn1","66"=>"","62"=>"sn2","64"=>"sn3");
echo '<pre>';
print_r($arr1);
echo '</pre>';

?>

Returns:

Array
(
[22] =>
[19] => sn1
[66] =>
[62] => sn2
[64] => sn3
)

What I need is that I’m going to save both values at once

This part makes me wonder how this is going to be stored…

I don’t see anything that’s relatable based on what your final output should be. Can you explain further?

I always thought that I got the real problem.
I found myself here, asking questions and answered by questions.
I asked myself too about it. When I repeat my question
over and over. I’m lost and didn’t understand too.

After how many hours,days. I manage to find the simple solution.
Now I realized that 90% of the solution is in the question.
Thank you for the responses.

I hope I know the ‘I’ that knows what I know.

It would be interesting to know what your simple solution consisted of?

i’m gonna guess instead of trying to merge it all… if([FPHP]in_array[/FPHP])…