Running into a problem where I can access every other property of this stdClass object except for the first. I am taking data from an uploaded csv and turning it into an array. from the array I am them converting it to an object. Code below
case($_FILES['csv_upload'] != NULL);
$data = [];
$csv = array_map('str_getcsv', file($_FILES['csv_upload']['tmp_name']));
$header = array_map('strtolower' , $csv[0]);
foreach($csv as $row)
{
$row = preg_replace("/[\$,]/", "", $row );
$data[] = array_combine($header, $row);
}
$layout->items = json_decode(json_encode($data), FALSE);
//unsetting the headers
unset($layout->items[0]);
this gives me an array of stdClass objects. When I do a foreach, I am able to access every property of the object except for the first one (id). A print_r($layout->items) returns the below
Array
(
[1] => stdClass Object
(
[id] => 253
[fet] => 157.50
[salecost] => 78.75
[price] => 157.50
[retail] => 0
)
[2] => stdClass Object
(
[id] => 243
[fet] => 150.00
[salecost] => 75
[price] => 150.00
[retail] => 0
)
a vardump returns the below
array(47) { [1]=> object(stdClass)#2856 (5) { ["id"]=> string(6) "253" ["fet"]=> string(10) " 157.50 " ["salecost"]=> string(5) "78.75" ["price"]=> string(8) "157.50 " ["retail"]=> string(1) "0" } [2]=> object(stdClass)#243 (5) { ["id"]=> string(6) "245815" ["fet"]=> string(8) "150.00 " ["salecost"]=> string(2) "75" ["price"]=> string(8) "150.00 " ["retail"]=> string(1) "0" }
I need to be able to access the 'id' property but, when I try to, it does not return anything, however, I can access any other property in the object and it returns correctly. I'm stumped.