See if anyone can solve my problem. I might be going about this the wrong way but...

I've just called an array out of a database and unserialized it (no problem here). Then I want to break it up into multiple arrays based on values from the first array.
for example:
The first array is: $db = ("a0" => "on");
I need an array: $a = ("a0 => "on); and so on.

Here is some code that makes sense to me, but there's an error with the variablevariable line:
Fatal error: Cannot use [] for reading in FILE

$db = array ("a0"=>"on","a5"=>"on", "b2"=>"on","b8"=>"on", "c4"=>"on","c5"=>"on", "d0"=>"on","d9"=>"on");
foreach ($db as $key => $value)
{
$letter = substr($key,0,1);
$number = substr($key,1);
$$letter[] = $letter$number => $value;
}

    $$letter[] = $letter$number => $value;

    change that to:

    $$letter[] = $letter.$number." => ".$value;

    i think it was trying to use the => operator which dosent work out side of an array() of course. you had to add it in quotes.

    hth
    moon

      I'm still getting the same error:
      Fatal error: Cannot use [] for reading in FILE

      Do me this says it doesn't like using the variablevariable or [].

        that's really wierd cuz ur not doing any file()s or fread()s as far as i can c......... and ya you should make it $var.$var2.$var3

        sry i canthelp more...

          Originally posted by Neumy
          $$letter[] = $letter$number => $value;

          I think you might be wanting

          $$letter[$letter.$number] = $value;
          

            that's a good point i hadnt thought of that but wouldnt it just be:

            $$letter[$number] = $value;

            for something like:

            $a[0]

            ?

            moon

              ${$letter}[$letter.$number] = $value

                Originally posted by Moonglobe
                that's a good point i hadnt thought of that but wouldnt it just be:

                $$letter[$number] = $value;

                [/B]

                Quite possibly; I don't really understand what's being asked for well enough to be sure (like isn't $letter.$number just going to be equal to $key anyway?)

                  Write a Reply...