-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
  • 9
    No, there is not, arrays CANNOT have duplicate keys. Commented Apr 8, 2016 at 11:14
  • can't you have ? array( [1] => array( [0]=>SAL121 , [1]=> SAL122, [2]=>SAL 145 ...) Commented Apr 8, 2016 at 11:16
  • 1
    poosible duplicate of stackoverflow.com/questions/5445283/… Commented Apr 8, 2016 at 11:16
  • 3
    Maybe it would be better if you explained what you are trying to achieve by combining these 2 arrays, then we could suggest something useful Commented Apr 8, 2016 at 11:19
  • 1
    Possible duplicate of PHP Associative Array Duplicate Key? Commented Apr 8, 2016 at 11:35

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 ) ) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.