bwouters Posted October 12, 2013 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 Link to comment Share on other sites More sharing options...
dsonesuk Posted October 12, 2013 Share Posted October 12, 2013 "link" => $row["link"], its expecting another array item Link to comment Share on other sites More sharing options...
bwouters Posted October 12, 2013 Author Share Posted October 12, 2013 Thanks, however I am still receiving the same error msgs. Link to comment Share on other sites More sharing options...
Ingolme Posted October 12, 2013 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 Link to comment Share on other sites More sharing options...
bwouters Posted October 12, 2013 Author 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 Link to comment Share on other sites More sharing options...
bwouters Posted October 12, 2013 Author 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"] ); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now