-3

I have an array like

$sele_itmid = Array
(
    [0] => 1
    [1] => 1
    [2] => 1
    [3] => 4
    [4] => 4
)
$fltrd_serl_batch = Array
(
    [0] => SAL121
    [1] => SAL122
    [2] => SAL 145
    [3] => M121
    [4] => M122
)

At this time i need to combine them like $sele_itmid values as keys $fltrd_serl_batch some thing like

array(
    [1] => SAL121
    [1] => SAL122
    [1] => SAL 145
    [4] => M121
    [4] => M122
)

I know cant use array_combine because it wont accept duplicate keys. what is the other way to do this? Is there any array function to do this?

7

1 Answer 1

1
$itm_btch = array_map(function($key, $val) {return array($key=>$val);}, $sele_itmid, $fltrd_serl_batch);

print_r($itm_btch );
Array
(
    [0] => Array
        (
            [1] => SAL122
        )

    [1] => Array
        (
            [1] => SAL 145
        )

    [2] => Array
        (
            [4] => M121
        )

    [3] => Array
        (
            [4] => M122
        )

)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.