I need to create an array from a csv file that looks like this.
$responseMessages = array(
'111111' => array('body' => 'test me, We will give you up to 3001 for your 2010 toyota camry. Visit http://testme.whatever.com or call +17777777777'),
'222222' => array('body' => 'test you, We will give you up to 3002 for your 2011 nissan maxima. Visit http://testyou.whatever.com or call +17777777777'),
'333333' => array('body' => 'test him, We will give you up to 3003 for your 2012 honda civic. Visit http://testhim.whatever.com or call +17777777777'),
'444444' => array('body' => 'test her, We will give you up to 3004 for your 2013 hyundai sonata. Visit http://testher.whatever.com or call +17777777777'),
'555555' => array('body' => 'test them, We will give you up to 3005 for your 2014 subaru legacy. Visit http://testthem.whatever.com or call +17777777777'),
'666666' => array('body' => 'test us, We will give you up to 3006 for your 2015 acura integra. Visit http://testus.whatever.com or call +17777777777')
);
The csv looks like this:
first last year make model value code url
test me 2010 toyota camry 3001 111111 http://testme.whatever.com
test you 2011 nissan maxima 3002 222222 http://testyou.whatever.com
test him 2012 honda civic 3003 333333 http://testhim.whatever.com
test her 2013 hyundai sonata 3004 444444 http://testher.whatever.com
test them 2014 subaru legacy 3005 555555 http://testthem.whatever.com
test us 2015 acura integra 3006 666666 http://testus.whatever.com
This is the php i'm using:
$phone = "+17777777777";
$handle = fopen("test.csv", "r");
$row = 0;
$responseMessages = array();
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE && $row < 8) {
if ($data[6] !== "code") { //leave out header line
$code = $data[6];
$upc = $data[0]." ".$data[1].", We will give you up to ".$data[5]." for your ".$data[2]." ".$data[3]." ".$data[4].". Visit ".$data[7]." or call ".$phone;
$responseMessages['\''.$code.'\'']['\'body\''] = '\''.$upc.'\'';
$row++;
}
}
echo "<pre>";
print_r( $responseMessages );
echo "</pre>";
This is the array that is being produced:
Array
(
['111111'] => Array
(
['body'] => 'test me, We will give you up to 3001 for your 2010 toyota camry. Visit http://testme.whatever.com or call +17777777777'
)
['222222'] => Array
(
['body'] => 'test you, We will give you up to 3002 for your 2011 nissan maxima. Visit http://testyou.whatever.com or call +17777777777'
)
['333333'] => Array
(
['body'] => 'test him, We will give you up to 3003 for your 2012 honda civic. Visit http://testhim.whatever.com or call +17777777777'
)
['444444'] => Array
(
['body'] => 'test her, We will give you up to 3004 for your 2013 hyundai sonata. Visit http://testher.whatever.com or call +17777777777'
)
['555555'] => Array
(
['body'] => 'test them, We will give you up to 3005 for your 2014 subaru legacy. Visit http://testthem.whatever.com or call +17777777777'
)
['666666'] => Array
(
['body'] => 'test us, We will give you up to 3006 for your 2015 acura integra. Visit http://testus.whatever.com or call +17777777777'
)
)
Kind of looks right, but not really. Not sure if i need the commas that are between each array, or if the word array needs to be lowercase, but the main thing is all the ['body'] tags can't have brackets, and no brackets around the codes either. Can you tell me what i'm doing wrong, and if there is a different array creation method I need to be using, and what that is? Thank you.