I've written a PHP function that reads in a file of orders and stores them into an array. When I load my web page, I am getting:
Notice: Undefined index: id on line 112
which is the final $orders[$order['id']] = $order;
Here's my function code
function readOrders($filename)
{
$arr = file($filename) or die('ERROR: Cannot find file');
$delimiter = ',';
// reading in customers from file and storing in array of customers
foreach ($arr as $line) {
$splitcontents = explode($delimiter, $line);
$order = array();
$orders['id'] = $splitcontents[1];
$orders['isbn'] = $splitcontents[2];
$orders['title'] = utf8_encode($splitcontents[3]);
$orders['category'] = utf8_encode($splitcontents[4]);
$orders[$order['id']] = $order;
}
return $orders;
}