I'm trying to break up a single array into multiple arrays. My main array would look similar to this:
$db = array("a0"=>"on","a4"=>"on","b1"="off","b8"=>"on",...);
My goal is to explode this array into arrays with names such as $a, $b, $c, etc. The values within these arrays should be similar to the above array, similar to this:
$a = array("a0=>"on","a4=>"on");
$b = array("b1"=>"off","b8"=>"on");
...
Here is my code:
<?php
$db = array ("a0"=>"on","a5"=>"on","a9"=>"on", "b2"=>"on","b8"=>"on", "c4"=>"on","c5"=>"on", "d0"=>"on","d9"=>"on");
echo "DB = "; var_dump($db); echo "<br>";
foreach ($db as $key => $value)
{
$letter = substr($key,0,1);
$number = substr($key,1);
$$letter .= $key.",";
}
$a = explode(',',$a);
$b = explode(',',$b);
$c = explode(',',$c);
$d = explode(',',$d);
echo "<br>A = "; var_dump($a);
echo "<br>B = "; var_dump($b);
echo "<br>C = "; var_dump($c);
echo "<br>D = "; var_dump($d);
?>
This code almost works, I'm creating an array such as:
$a = array ([0]=>"a0",[1]=>"a4")
$b = array ([0]=>"a1",[1]=>"a8")
As you can see, this is not what I need. Is there any way to explode keys and values??
Any help would be appreciated, I've been working on this code for a couple of days and am going insane😕
Thanks for any help!