• New Commercial Services Section

    We have now opened a commercial services section here on the forum. If you have a Fabrik project that you wish to have someone work on for you, post it under Help Wanted. If you are an application developer and wish to earn some money helping others, post your details under Fabrik Application Developers.

    Both of these are unmoderated. It will be up to both parties to work out the details and come to an agreement.

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.

Members online

Back
Top