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?
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.
Comments