bpgillett Posted April 17, 2007 Share Posted April 17, 2007 i'm trying to process 2 numerically indexed arrays, one of which is multidimensional, to result in an indexed array of associative arrays. the values from array #1 would ultimately be paired with any values contained in the nested array of corresponding numerical index from array #2. nested arrays that are empty in array #2 would be ignored. Array #1: $array1 = Array ( [0] => Below Expectation [1] => Meets Expectation [2] => Above Expectation ) Array #2: $array2 = Array ( [0] => Array ( [1] => pc [2] => p ) [1] => Array ( [1] => mk [2] => ics [3] => sbl ) [2] => Array ( ) Goal Array $arrayFinal = Array ( [0] => Array ( ['pc'] => Below Expectation ['p'] => Below Expectation ) [1] => Array ( '[mk'] => Meets Expectation ['ics'] => Meets Expectation ['sbl'] => Meets Expectation ) [2] => Array ( ) i'm really pulling out my hair on this one as i can't even figure the conceptual approach; any help would be great. thanks, brian Quote Link to comment Share on other sites More sharing options...
Barand Posted April 17, 2007 Share Posted April 17, 2007 try <?php $array1 = array ( 0 => 'Below Expectation', 1 => 'Meets Expectation', 2 => 'Above Expectation' ); $array2 = array ( 0 => array ( 1 => 'pc', 2 => 'p' ), 1 => array ( 1 => 'mk', 2 => 'ics', 3 => 'sbl' ), 2 => array ( ) ); $result = array(); foreach ($array2 as $k => $subarray) { foreach ($subarray as $item) { $result[$k][$item] = $array1[$k]; } } echo '<pre>', print_r($result,true), '</pre>'; ?> Quote Link to comment Share on other sites More sharing options...
bpgillett Posted April 18, 2007 Author Share Posted April 18, 2007 wow...perfect. thanks again. --brian Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.