Here, I m using PHPexcel library to reading the file. My excel File look like
Controller
class Home extends CI_Controller {
public function index() {
$this->load->library('excel');
$reader = PHPExcel_IOFactory::createReader('Excel2007');
$reader->setReadDataOnly(true);
$file = isset($_FILES["uploadexcel"]['tmp_name']) ? $_FILES["uploadexcel"]['tmp_name'] : '';
$excel = $reader->load($file);
foreach ($excel->getWorksheetIterator() as $worksheet) {
$worksheets = $worksheet->toArray();
}
echo '<pre>';print_r($worksheets);
}
}
when I am uploading excel file my array like:
Array
(
[0] => Array
(
[0] => url
[1] => category_1
[2] => category_2
[3] => language
[4] => f_n
[5] => publishers
[6] => cost
[7] => cost_currency
[8] => processing_time
[9] => example
[10] => note
)
[1] => Array
(
[0] => gettingaway.com
[1] => 10
[2] => 14
[3] => GA
[4] => nofollow
[5] => 2
[6] => 1245
[7] =>
[8] => 12
[9] => testing
[10] => Testing Value
)
)
But, I want the array like :
Array
(
[0] => Array
(
[url] => gettingaway.com
[category_1] => 10
[category_2] => 14
[language] => GA
[f_n] => nofollow
[publishers] => Cust Angel
[cost] => 12
[cost_currency] => USD
[processing_time] => 12
[example] => example
[note] => note
)
[1] => Array
(
[url] => thebusbench.com
[category_1] => 5
[category_2] => 13
[language] => GA
[f_n] => nofollow
[publishers] => Cust Angel
[cost] => 12
[cost_currency] => USD
[processing_time] => 6
[example] => example
[note] => note
)
[2] => Array
(
[url] => travelintelligence.net
[category_1] => 6
[category_2] => 11
[language] => GA
[f_n] => nofollow
[publishers] => Cust Angel
[cost] => 12
[cost_currency] => USD
[processing_time] => 2
[example] => example
[note] => note
)
)
In above array, my publisher key value is 2. i.e. the Id of publisher into my database. I want this related id publisher name into array. In my database id 2 related publisher name is Cust Angel.