I am trying a add data to an array using a while loop but it seems to be adding the data as a string not array. Loops/arrays are something I'm still learning any help would be great.
$c = 0;
$numberofcustom = 5;
$defaults = array(
'title' => __('Follow Us!', 'smw'),
'text' => ''
);
while ($c < $numberofcustom) {
$customnumber = $c + 1;
$defaults.=array(
'custom' . $customnumber . 'name' => __('', 'smw'),
'custom' . $customnumber . 'icon' => __('', 'smw'),
'custom' . $customnumber . 'url' => __('', 'smw')
);
$c++;
}
print_r($defaults);
The problem seems to be with adding the data from the loop if I do a print_r
just on that I just get "array" back.
Any help would be appreciated.
UPDATE
I decided I don't need a multi dimensional array so I used the suggestions below and came up with
while( $c < $numberofcustom){
$customnumber = $c+1;
$defaults['custom'.$customnumber.'name'] = __('', 'smw');
$defaults['custom'.$customnumber.'icon'] = __('', 'smw');
$defaults['custom'.$customnumber.'url'] = __('', 'smw');
$c++;
}
Copyright Notice:Content Author:「Brooke.」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/7460356/adding-data-to-an-array