1

I am trying to extract a custom field from a contact record. The API returns an array of the following form:

Array (
    [0] => 0
    [1] => 3
    [2] => array (
        [0] => array (
            [value 1] => 123
            [value 2] => 456
            [value 3] => 789
)))

Using php how can I extract value 1, 2 or 3?

Later information

This is the actual array

Array (
[0] => 0
[1] => 3
[2] => 1
[3] => 2911
[4] => Array (
    [0] => Array (
        [contact_id] => 2911
        [civicrm_value_aru_data_1_id] => 2586
        [custom_64] => 2014848
        [id] => 2911

)))

and I want to extract the value of custom_64. I am using:

$rugby_id = $arrayvariable[4][0][custom_64];

which returns nothing and I can't see where I am going wrong.

Even later information

I am still struggling with this issue. In an attempt to simplify things I have changed the CiviCRM API call to 'getsingle' and stored the result as follows:

$results = print_r($result, true);
echo $results;

which leads to the following:

Array (
[contact_id] => 2911 
[civicrm_value_aru_data_1_id] => 2586 
[custom_64] => 2014848 
[id] => 2911 
) 

If I now try to extract the value of custom_64 using:

$rugby_id = $results['custom_64'];

The value returned is 'A'. I have researched this to death but have not found the cause of the problem.

1

In the example you have given the way you would is

$arrayvariable[2][0][value 1] etc etc.

You can see an example here for usage from CiviCRM API v3 https://docs.civicrm.org/dev/en/latest/api/options/#sequential

0

I solved this problem by using a different CiviCRM API3 call so that I did not need to extract a value from an array. Instead in the API Explorer I selected the entity 'contact' and action 'getvalue'. I then selected the field that I wanted and that returned a single value which I was able to use without the need to use any array processing. In essence I walked around the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.