473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Cannot use string offset as an array

I get an error message like this.

Fatal error: Cannot use string offset as an array in D:\www\site\includes\change_preference.inc.php on line 310

[PHP]$cityName["$i"]["$j"] = $row2['city'];[/PHP]
The above code is causing this error. Please let me know what is wrong with this code. How can I rectify this error.

Here $i, $j consists of integer value. which are used to perform a for loop specific number of times. while $row2 brings data from a database.
Nov 4 '08 #1
5 4588
Dormilich
8,658 Expert Mod 8TB
try $cityName's keys without the quotation marks. if that's not working use var_dump() to check for variable type and content.
Nov 4 '08 #2
Markus
6,050 Expert 4TB
Somewhere else you are declaring $cityName as a string and not a variable.

Post the full code using code tags.
Nov 4 '08 #3
I found which caused the error.
I have used a variable name similar to the array name $cityName that caused the confusion.

[PHP]$cityName = 'Dallas';
$cityName["$i"]["$j"] = $row2['city'];
[/PHP]
first I have used the $cityName as a string and then as an array which caused the error. I did not realize this because the above two lines were in different files and was included in another file. I think I should keep more appropriate names depending upon the file and context.
Nov 4 '08 #4
Somewhere else you are declaring $cityName as a string and not a variable.

Post the full code using code tags.
Oh! Thanks Markus. I did not see the post of yours. But anyhow I got it sorted out. great relief. Thank you very much!

and thank you too Dormilich
Nov 4 '08 #5
Markus
6,050 Expert 4TB
I found which caused the error.
I have used a variable name similar to the array name $cityName that caused the confusion.

[PHP]$cityName = 'Dallas';
$cityName["$i"]["$j"] = $row2['city'];
[/PHP]
first I have used the $cityName as a string and then as an array which caused the error. I did not realize this because the above two lines were in different files and was included in another file. I think I should keep more appropriate names depending upon the file and context.
As I said above. :)
Nov 4 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Andrew | last post by:
I have written two classes : a String Class based on the book " C++ in 21 days " and a GenericIpClass listed below : file GenericStringClass.h // Generic String class
5
by: overbored | last post by:
I can do this: int asdf; int* zxcv = asdf; but not this: int asdf; int** zxcv = asdf;
2
by: Vince | last post by:
I have a very specific problem to solve but I cannot find a data structure for it. I don't know if I am posting on the good newsgroup but I cannot find a software.design group. I would like to...
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
14
by: Jon Davis | last post by:
I have put my users through so much crap with this bug it is an absolute shame. I have a product that reads/writes RSS 2.0 documents, among other things. The RSS 2.0 spec mandates an en-US style...
8
by: Jami Bradley | last post by:
Hi, I'm looking for an efficient way to do this, because I know it will be heavily used :-) I have a fixed width string and I need to substitute a substring of characters with new values. I...
1
by: Jim Michaels | last post by:
=> Array ( => UML:CLASS => open => 5 => Array ( => .:00000000000008EC => quiz_batteries => public
4
by: ThunderMusic | last post by:
Hi, I have a custom form that works fine when I debug it or run it in release mode but cannot be loaded in the designer... Actually, it can be loaded in the designer when no control is on it, but...
9
by: herobeat | last post by:
Hi all, I'm having a hell of a time with declaring a struct to hold some binary data I'm trying to read from some files on disk. What I would like to do is something like this: public struct...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.