Jump to content
xisto Community
moldboy

Fatal Error something about [] and strings

Recommended Posts

I have this variable that I want to take the value of to use as an array, now it is a slightly odd variable it's one that I get by combinin a word and a number and then calling the information stored in that var, so ${${word . $number}}, anywho I get the following errorFatal error: [] operator not supported for strings in and then the path

Share this post


Link to post
Share on other sites

Can you put little more code :D from this i see only FatalError :unsure: and no idea what you try to do :Dbut ...Array ID can got only numbersNameImage[1] = "one";NameImage[2] = "two";...so ...$id = 'bolek';$number = 1.$id;NameImage[$number] give you error :P$id = 5;$number = 1*$id; //give(5) or $number = 1.$id; //give(15)NameImage[$number]; give you value from arrayif this not give you answer put more code and write cleary what you wanna do :D--------------------Practice is when evrything is work but no one know why.Theory is when work nothing but evry one know why.Programmers join Practice with Theory - nothing work and no one know why :P

Share this post


Link to post
Share on other sites

I've actualy changed my array structuring system to use the array() function But I post what I wanted to do anyway,
Let's pretend that I have 3 pages, on the first page the user enters a number, we'll say 4
on the next page using a while loop and code simmilar to the following the page generates a form field with 4 text boxes:

//form junk up here, don't feel like typing$break = 0$number = 1while ($userinput > $break){echo "<tr>";echo "<input type=\"text\" name=\"inputarr" . $number . "\">";echo "</tr>";break++;number++;}//bunch more code here
THis would build frou text inputs with the variables inputarr1 inputarr2 inputarr3 inputarr4.

Now I wanted to store information in an array form in the values that the user entered, so if inputarr1 was cookie, I want to create a array called $cookie with information, so:
${${inputarr . $number}}[] = whatever information;
bearing in mind that the $number would be deffined simmilar to the above example. This returned an error, the funny thing is I built this and it worked relativly well it didn't return the final output I wanted but no errors, so I went to watch TV and make a more complex example and when I cam back I recieved an error so I tried my simple example again and I go the same error, but now I've switched to using the array() function it workes like it did, not the correct answer but an answer.

Share this post


Link to post
Share on other sites

Isn't it easier to do it in a way like this:

<?$var1 = "foo";$var2 = "bar";$foobar = "the_thing_you_want";eval("\$finalvar = \$".$var1.$var2.";");echo $finalvar;?>

The code above will write the_thing_you_want on the screen

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.