how to obtain the first value of element in a repeteable group

javier94

Member
hello,

i have an element inside of a repeteable group..

I'm using this code... to obtain the value of this element

$tot = '{merits_candidats_815_repeat___suma_repetible}';
return $tot;

right now there are 4 registers in this repeteable.. so the value obtained.. is

54, 54, 54, 54

i would like to obtain only the first value.. but if is possible only changing the variable
$tot = array [0] ('{merits_candidats_815_repeat___suma_repetible}' ); --> (something similar to this) but i can not find the right code...

Any suggestion??

thanks in advance!

javier
 
What type of element?

If you are getting a comma separated string of values, one way is to convert that to an array ...

Code:
$tot = '{merits_candidats_815_repeat___suma_repetible}';
$tot = explode(',', $tot);
return $tot[0];

-- hugh
 
Although to be safe, in case the group is empty, to avoid a PHP warning about index 0 not existing ...

Code:
$tot = '{merits_candidats_815_repeat___suma_repetible}';
$tot = explode(',', $tot);
return ArrayHelper::getValue($tot, 0, '');

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top