Campaign List Count is Incorrect

Using the API, I perform a count on the total number of lists in my account, but it returns an incorrect count when there are less than 2 lists.

When I perform a count($result_client_list['anyType']['List']);  I get the following result:

If 1 lists exists, the returned result is: 2
if 2 lists exists, the returned result is: 2
if 3  lists exists, the returned result is: 3

As you can see, if there is only one list, the count will show two lists.

Am I counting the correct array to show me the total number of lists?

Mathew Mathew, 7 years ago


We've actually followed up with you via your support ticket for this one. For future reference, this is related to the way the PHP API wrapper converts the XML response into multi-dimensional PHP array.

Basically to get around this, you need to check for the existence of an element at index 0 in the List array:

e.g. (Assuming that $result_client_list['anyType']['List'] exists):

$count = array_key_exists(0, $result_client_list['anyType']['List']) ? count($result_client_list['anyType']['List']) : 1;

It is a bit more difficult than it really should be, but that is one of the difficulties when converting XML into a PHP data structure.

Get in touch with us on Twitter:
We're also on Facebook:

200,000 companies around the world can't be wrong.

From Australia to Zimbabwe, and everywhere in between, companies count on 
Campaign Monitor for email campaigns that drive real business results.

Get started for free