bwouters 0 Posted October 12, 2013 Report Share Posted October 12, 2013 (edited) Dear reader, On my own server I created the following code that is working perfectly: $items = []; foreach ($rows as $row) { $items[] = [ "item" => $row["item"], "brand" => $row["brand"], "number" => $row["number"], "price" => $row["price"], "start" => $row["start"], "end" => $row["end"], "shop" => $row["shop"], "location" => $row["location"], "link" => $row["link"] ]; } However my hosting party is not supporting php 5.4 and therefor I transformed the code in: $items = array(); foreach ($rows as $row) { $items = array("item" => $row["item"], "brand" => $row["brand"], "number" => $row["number"], "price" => $row["price"], "start" => $row["start"], "end" => $row["end"], "shop" => $row["shop"], "location" => $row["location"], "link" => $row["link"] ); } and now I am getting the error msgs: "Uninitialized string offset: 0". Does anyone knows what I am doing wrong? Thanks inadvance for your help!!! Edited October 12, 2013 by bwouters Quote Link to post Share on other sites
dsonesuk 913 Posted October 12, 2013 Report Share Posted October 12, 2013 "link" => $row["link"], its expecting another array item Quote Link to post Share on other sites
bwouters 0 Posted October 12, 2013 Author Report Share Posted October 12, 2013 Thanks, however I am still receiving the same error msgs. Quote Link to post Share on other sites
Ingolme 1,020 Posted October 12, 2013 Report Share Posted October 12, 2013 On thing I notices is that you still need the square backets here in order to add elements to the array: $items[] = array( As for the uninitialized string offset error, check and make sure that $row isn't a string. 1 Quote Link to post Share on other sites
bwouters 0 Posted October 12, 2013 Author Report Share Posted October 12, 2013 Dear Ingolme, Thank you so much!!! I spent hours looking at it and now due to your help it is working. I am really really thankful with your help!! Bart Quote Link to post Share on other sites
bwouters 0 Posted October 12, 2013 Author Report Share Posted October 12, 2013 The answer: $items = array(); foreach ($rows as $row) { $items[] = array("item" => $row["item"], "brand" => $row["brand"], "number" => $row["number"], "price" => $row["price"], "start" => $row["start"], "end" => $row["end"], "shop" => $row["shop"], "location" => $row["location"], "link" => $row["link"] ); } Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.