-2

User Array

print_R($user_array);
Array
(
    [0] => Array
        (
            [SKILL_NAME] => Application Software
            [EXPERIENCE_BAND] => 15+
            [SITE_STATUS] => Onsite
            [NO_OF_RESOURCE] => 1
            [ACTUAL_HOURS] => 16
        )

    [1] => Array
        (
            [SKILL_NAME] => Application Software
            [EXPERIENCE_BAND] => 2-4
            [SITE_STATUS] => Onsite
            [NO_OF_RESOURCE] => 1
            [ACTUAL_HOURS] => 96
        )

)

Value Array

print_R($value_array);
Array
(
    [RATE_PER_HOUR] => 80,50
    [MARKUP_PERCENT] => 5,10
    [TOTAL_COST] => 8064.00,880.00
)

Exploding Value array RATE_PER_HOUR

$rate_per_hour = explode(',', $array_data['RATE_PER_HOUR']);

ouputs below. The same goes for MARKUP_PERCENT and TOTAL_COST

Array
(
    [0] => 80
    [1] => 50
)

How could I map above two arrays so that the output is like below. Array mapping is done based on key to maintain the correct data.

Array
(
    [0] => Array
        (
            [SKILL_NAME] => Application Software
            [EXPERIENCE_BAND] => 15+
            [SITE_STATUS] => Onsite
            [NO_OF_RESOURCE] => 1
            [ACTUAL_HOURS] => 16
            [RATE_PER_HOUR] => 80
            [MARKUP_PERCENT] => 5
            [TOTAL_COST] => 8064.00
        )

    [1] => Array
        (
            [SKILL_NAME] => Application Software
            [EXPERIENCE_BAND] => 2-4
            [SITE_STATUS] => Onsite
            [NO_OF_RESOURCE] => 1
            [ACTUAL_HOURS] => 96
            [RATE_PER_HOUR] => 50
            [MARKUP_PERCENT] => 10
            [TOTAL_COST] => 880.00
        )

)
Slimshadddyyy
  • 4,085
  • 5
  • 59
  • 121

1 Answers1

0

Explode each value in the Value array. Loop through this and add them to the corresponding element of the User array.

foreach ($value_array as $key => $data) {
    $data_array = explode(',', $data);
    foreach ($data_array as $index => $val) {
        $user_array[$index][$key] = $val;
    }
}

DEMO

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thanks for responding. I have exploded array for specific keys which need to be added in main `user_array`. I could not figure out how exactly to use above snippet to generate expected output. How should I go about it considering above arrays ? – Slimshadddyyy Aug 27 '15 at 12:15
  • Just change `$value` for `$value_array` and `$user` to `$user_array`, semantics. – al'ein Aug 27 '15 at 12:27
  • @Slimshadddyyy I've fixed my answer to use your array names. – Barmar Aug 27 '15 at 12:30
  • Where do you set `$data_array` in your updated code? – Barmar Aug 27 '15 at 12:32