I am trying to query database and keep count of records that have the same data in the campaign field. I am using an array to store counts. I first check to see if data from database is in the array. If it is not, add to the array as key and value of 1, if the data is already an key, increment value by 1. I am getting an error Fatal error: Cannot use assign-op operators with overloaded objects nor string offsets in on line 18
<?php
include 'database/dbinfo.php';
$campaignCalls = array();
//Connect to database
$con=mysqli_connect("localhost",$username,$password,$database);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//Query records from database
$result = mysqli_query($con, "SELECT * FROM `phone_records` ");
while($row = mysqli_fetch_array($result))
{
$campaign = $row['campaign'];
//Check to see if data of field campaing is in array, if so increment by 1
if (array_key_exists($campaign, $campaignCalls)){
$campaign[$campaignCalls] += 1;
}
//Add key and value to array
else {
$campaignCalls[$campaign] = 1;
}
}
mysqli_close($con);
?>