2

I am learning php. I have an array as:

Array ( [0] => 160 [1] => 380 [2] => 180)

I have to convert this array to a string. I am aware of implode. But it joins all the array elements with a string. But if i have to join just the first 2 elements or specific elements which method should i use.? Am i missing something?

1 Answer 1

1

using array_slice will enable you join a part of an array:
http://php.net/manual/en/function.array-slice.php

$array = array(100, 200, 300);
echo implode( '-', array_slice($array,0,2) );
Sign up to request clarification or add additional context in comments.

1 Comment

Why is array_splice preferable over array_slice?

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.