define keys in multidimensional array from csv

Posted by mourique on Stack Overflow See other posts from Stack Overflow or by mourique
Published on 2010-04-12T13:44:43Z Indexed on 2010/04/12 13:53 UTC
Read the original article Hit count: 295

Filed under:
|

I want to compare two arrays, one coming from a shoppingcart and the other one parsed from a csv-file. The array from the shopping cart looks like this:

Array
(
    [0] => Array
        (
            [id] => 7
            [qty] => 1
            [price] => 07.39
            [name] => walkthebridge
            [subtotal] => 7.39
        )

    [1] => Array
        (
            [id] => 2
            [qty] => 1
            [price] => 07.39
            [name] => milkyway
            [subtotal] => 7.39
        )
)

The array from my csv-file however looks like this

Array
(
    [0] => Array
        (
            [0] => 1
            [1] => walkthebridge
            [2] => 07.39
        )

    [1] => Array
        (
            [0] => 2
            [1] => milkyway
            [2] => 07.39
        )

)

and is build using this code

$checkitems = array();
    $file = fopen('checkitems.csv', 'r');

          while (($result = fgetcsv($file)) !== false) {

          $checkitems[] = $result;
          }

    fclose($file);

how can i get the keys in the second array to match those in the first one? ( So that 0 would be id, and 1 would be name and so on)

thanks in advance

© Stack Overflow or respective owner

Related posts about php

Related posts about csv