I am trying to build a form where user inputs a data from a string and the form will get subsets of data through json src based on the input and create a multidimensional array and save it in database. If the input was previously added to database, I dont want it to append in the array again.
Here is how my code looks:
//SET UP the Array
$thisquery_themes[] = array(
strtolower($themename) => array(
"author"=>$data['Author'],
"desc"=>$data['Description'],
"screenshot"=> $screenshot,
"link"=> $data['URI'],
"count"=> 1
)
);
//Get Previously saved data
$existing_themes = get_option('top_themes');
if(!empty($existing_themes)){
foreach ($existing_themes as $group){
foreach(array_keys($group) as $key) {
if($group[strtolower($themename)] == strtolower($themename)){
unset($group[$key][strtolower($themename)]);
}
}
}
$total_themes= array_merge($existing_themes , $thisquery_themes);
update_option('top_themes', $total_themes);
} else {
update_option('top_themes', $thisquery_themes);
}
its not. if the key exist in the array, the data is still being added in the array:
Array (
[0] => Array (
[towfiq-i._v5] => Array (
[author] => Towfiq I.
[desc] => Towfiq I. official website.
[count] => 1
)
)
[1] => Array (
[towfiq-i._v5] => Array (
[author] => Towfiq I.
[desc] => Towfiq I. official website.
[count] => 1
)
)
[2] => Array (
[wp-bangla] => Array (
[author] => Ifty Rahman
[desc] => A website template for wpbangla
[count] => 1
)
)
[3] => Array (
[towfiq-i._v5] => Array (
[author] => Towfiq I.
[desc] => Towfiq I. official website.
[count] => 1
)
)
[4] => Array (
[wp-bangla] => Array (
[author] => Ifty Rahman
[desc] => A website template for wpbangla
[count] => 1
)
)
But I want it to be like this(Notice how "count" field value added up. let me know if its possible ):
Array (
[0] => Array (
[towfiq-i._v5] => Array (
[author] => Towfiq I.
[desc] => Towfiq I. official website.
[count] => 3
)
)
[1] => Array (
[wp-bangla] => Array (
[author] => Ifty Rahman
[desc] => A website template for wpbangla
[count] => 2
)
)
Any help would be greatly appreciated. Thanks