Forum Moderators: coopster
$cats['cpuamd']['basename'] = 'cpuamd';
$cats['cpuamd']['title'] = 'CPU AMD';$cats['cpuintel']['basename'] = 'cpuintel';
$cats['cpuintel']['title'] = 'CPU Intel';
foreach ($cats as $cat) {
$cat['table'] = 'zz_art_'.$cat['basename'];
$cat['det_table'] = 'zz_det_'.$cat['basename'];
}
$cats['cpuamd']['table'] = 'zz_art_cpuamd';
$cats['cpuamd']['det_table'] = 'zz_det_cpuamd';$cats['cpuintel']['table'] = 'zz_art_cpuintel';
$cats['cpuintel']['det_table'] = 'zz_det_cpuintel';
echo '<pre>';
print_r($cats);
echo '</pre>';
Array
(
[cpuamd] => Array
(
[basename] => cpuamd
[title] => CPU AMD
)[cpuintel] => Array
(
[basename] => cpuintel
[title] => CPU Intel
))
print_r($cats);right after your other would show you what I'm talking about.
print_r($cat);
Knowing that, you realize you probably want something like...
$cats[$cat]['table'] = 'zz_art_'.$cats[$cat]['basename'];...but that is going to throw you a warning because you cannot use arrays or objects as keys. Doing so will result in a warning: Illegal offset type. So how do you get them in there? Use array_keys() [php.net] in your foreach loop to return all the keys of the array first and use them accordingly.
$cats[$cat]['det_table'] = 'zz_det_'.$cats[$cat]['basename'];
foreach (array_keys($cats) as $cat) {
$cats[$cat]['table'] = 'zz_art_'.$cats[$cat]['basename'];
$cats[$cat]['det_table'] = 'zz_det_'.$cats[$cat]['basename'];
} Multidimensional arrays are fun, no doubt, but print_r is your friend. Helps you quickly troubleshoot what is going on at any given step in your script.