1

I have more than 10 values in my array.

I would like to separate it with comma.

So I used this code

echo implode(",", $array);

Can someone tell me how to limit the values.? I need only the first three values

1

2 Answers 2

9

slice the array first

$newArray = array_slice($array, 0, 3);
echo implode(',', $newArray);
Sign up to request clarification or add additional context in comments.

Comments

1

Using array_slice :

 $slicedArray = array_slice($array, 0, 3);
 $input=implode(",", $slicedArray);

1 Comment

The array_slice needs to be first

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.