Skip to main content
added 159 characters in body
Source Link

I have this function here:

<?php
public function assignData($data)
{
    $aSqlData['company'] = $data[0];
    $aSqlData['tx_trouserextend_contactperson'] = $data[1];
    $aSqlData['username'] = $data[2];
    $aSqlData['tx_trouserextend_commission'] = $data[3];
    $aSqlData['tx_trouserextend_wincap_version'] = $data[4];
    $aSqlData['tx_trouserextend_wincap_link'] = $data[5];
    $aSqlData['tx_trouserextend_contract_due'] = $data[6];
    $aSqlData['tx_trouserextend_pos_version'] = $data[7];
    $aSqlData['tx_trouserextend_pos_link'] = $data[8];
    $aSqlData['tx_trouserextend_quick_select_version'] = $data[9];
    $aSqlData['tx_trouserextend_quick_select_link'] = $data[10];
    $aSqlData['password'] = $data[11];

    $this->userdata = $aSqlData;
}

This goes on for like 10 more items with this way of assigning. Is there maybe a better way to iterate through it? For instance, just adding the indices and run assign every numerical index to the corresponding associative array-key?

Even though it works, it is not that nice to maintain, imho. Ideas how to improve this? As you can imagine, if the csv-file grows and gets more fields, I'd have to add a line of code for every new column. Thought there would/could be a better way.

I have this function here:

<?php
public function assignData($data)
{
    $aSqlData['company'] = $data[0];
    $aSqlData['tx_trouserextend_contactperson'] = $data[1];
    $aSqlData['username'] = $data[2];
    $aSqlData['tx_trouserextend_commission'] = $data[3];
    $aSqlData['tx_trouserextend_wincap_version'] = $data[4];
    $aSqlData['tx_trouserextend_wincap_link'] = $data[5];
    $aSqlData['tx_trouserextend_contract_due'] = $data[6];
    $aSqlData['tx_trouserextend_pos_version'] = $data[7];
    $aSqlData['tx_trouserextend_pos_link'] = $data[8];
    $aSqlData['tx_trouserextend_quick_select_version'] = $data[9];
    $aSqlData['tx_trouserextend_quick_select_link'] = $data[10];
    $aSqlData['password'] = $data[11];

    $this->userdata = $aSqlData;
}

This goes on for like 10 more items with this way of assigning. Is there maybe a better way to iterate through it? For instance, just adding the indices and run assign every numerical index to the corresponding associative array-key?

Even though it works, it is not that nice to maintain, imho. Ideas how to improve this?

I have this function here:

<?php
public function assignData($data)
{
    $aSqlData['company'] = $data[0];
    $aSqlData['tx_trouserextend_contactperson'] = $data[1];
    $aSqlData['username'] = $data[2];
    $aSqlData['tx_trouserextend_commission'] = $data[3];
    $aSqlData['tx_trouserextend_wincap_version'] = $data[4];
    $aSqlData['tx_trouserextend_wincap_link'] = $data[5];
    $aSqlData['tx_trouserextend_contract_due'] = $data[6];
    $aSqlData['tx_trouserextend_pos_version'] = $data[7];
    $aSqlData['tx_trouserextend_pos_link'] = $data[8];
    $aSqlData['tx_trouserextend_quick_select_version'] = $data[9];
    $aSqlData['tx_trouserextend_quick_select_link'] = $data[10];
    $aSqlData['password'] = $data[11];

    $this->userdata = $aSqlData;
}

This goes on for like 10 more items with this way of assigning. Is there maybe a better way to iterate through it? For instance, just adding the indices and run assign every numerical index to the corresponding associative array-key?

Even though it works, it is not that nice to maintain, imho. Ideas how to improve this? As you can imagine, if the csv-file grows and gets more fields, I'd have to add a line of code for every new column. Thought there would/could be a better way.

added 449 characters in body
Source Link

I have this function here:

<?php
public function assignData($data)
{
    $aSqlData['company'] = $data[0];
    $aSqlData['tx_trouserextend_contactperson'] = $data[1];
    $aSqlData['username'] = $data[2];
    $aSqlData['tx_trouserextend_commission'] = $data[3];
    $aSqlData['tx_trouserextend_wincap_version'] = $data[4];
    $aSqlData['tx_trouserextend_wincap_link'] = $data[5];
    ...$aSqlData['tx_trouserextend_contract_due'] = $data[6];
    $aSqlData['tx_trouserextend_pos_version'] = $data[7];
    $aSqlData['tx_trouserextend_pos_link'] = $data[8];
    $aSqlData['tx_trouserextend_quick_select_version'] = $data[9];
    $aSqlData['tx_trouserextend_quick_select_link'] = $data[10];
    $aSqlData['password'] = $data[11];

    $this->userdata = $aSqlData;
}

This goes on for like 20-3010 more items with this way of assigning. Is there maybe a better way to iterate through it? For instance, just adding the indices and run assign every numerical index to the corresponding associative array-key?

Even though it works, it is not that nice to maintain, imho. Ideas how to improve this?

I have this function here:

<?php
public function assignData($data)
{
    $aSqlData['company'] = $data[0];
    $aSqlData['tx_trouserextend_contactperson'] = $data[1];
    $aSqlData['username'] = $data[2];
    $aSqlData['tx_trouserextend_commission'] = $data[3];
    $aSqlData['tx_trouserextend_wincap_version'] = $data[4];
    $aSqlData['tx_trouserextend_wincap_link'] = $data[5];
    ...
}

This goes on for like 20-30 more items with this way of assigning. Is there maybe a better way to iterate through it? For instance, just adding the indices and run assign every numerical index to the corresponding associative array-key?

Even though it works, it is not that nice to maintain, imho. Ideas how to improve this?

I have this function here:

<?php
public function assignData($data)
{
    $aSqlData['company'] = $data[0];
    $aSqlData['tx_trouserextend_contactperson'] = $data[1];
    $aSqlData['username'] = $data[2];
    $aSqlData['tx_trouserextend_commission'] = $data[3];
    $aSqlData['tx_trouserextend_wincap_version'] = $data[4];
    $aSqlData['tx_trouserextend_wincap_link'] = $data[5];
    $aSqlData['tx_trouserextend_contract_due'] = $data[6];
    $aSqlData['tx_trouserextend_pos_version'] = $data[7];
    $aSqlData['tx_trouserextend_pos_link'] = $data[8];
    $aSqlData['tx_trouserextend_quick_select_version'] = $data[9];
    $aSqlData['tx_trouserextend_quick_select_link'] = $data[10];
    $aSqlData['password'] = $data[11];

    $this->userdata = $aSqlData;
}

This goes on for like 10 more items with this way of assigning. Is there maybe a better way to iterate through it? For instance, just adding the indices and run assign every numerical index to the corresponding associative array-key?

Even though it works, it is not that nice to maintain, imho. Ideas how to improve this?

Source Link

Assigning values from a numerical array to an associative array

I have this function here:

<?php
public function assignData($data)
{
    $aSqlData['company'] = $data[0];
    $aSqlData['tx_trouserextend_contactperson'] = $data[1];
    $aSqlData['username'] = $data[2];
    $aSqlData['tx_trouserextend_commission'] = $data[3];
    $aSqlData['tx_trouserextend_wincap_version'] = $data[4];
    $aSqlData['tx_trouserextend_wincap_link'] = $data[5];
    ...
}

This goes on for like 20-30 more items with this way of assigning. Is there maybe a better way to iterate through it? For instance, just adding the indices and run assign every numerical index to the corresponding associative array-key?

Even though it works, it is not that nice to maintain, imho. Ideas how to improve this?