ACF – Pick first or second value from comma separated values

You can use the explode() function to split a string into the array of values

So you have a string of colors, separated with a comma, where the comma is a delimiter:

$colors="Fiery Red, Leafy Green, Sky Blue";

Now use the explode() function (here is a link to the documentation) to convert it to the array:

$colors_array = explode( ', ', $colors );

As a result, you will get:

array(3)
(
    [0] => string(9) "Fiery Red"
    [1] => string(11) "Leafy Green"
    [2] => string(8) "Sky Blue"
)

Now, when you have an array of values, you can display only the first value:

echo $colors_array[0];

or the first two elements:

$output_array = array_slice( $colors_array, 0, 2 );

echo implode( ', ', $output_array );

tech