Convert only specific elements of an array to string in php

poorvank

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?

mgherkins

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) );

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related