I have a string like this $value[0] = "8000297c - 1360598144 "
I explode them into 2 pieces by doing this : $elements = explode('-', $value[0]);
Then I created 2 variables to store them :
$first = strtolower($elements[0]); // 8000297c
$last = strtoupper($elements[1]); // 1360598144
Now- after formatting them, I want to join them back to the original format like this
$first."-".$last
I was thinking to use implode()
function, and I tried
$polish_sku = implode("-", $first, $last);
- then, I got this :I hope someone don't mind and point out what I did wrong. :D
if you want to use implode
implode("-", array($first, $last));
or just concat them ?
$first . "-" . $last
or use printf/sprintf ?
printf("%s-%s", $first, $last)
$polish_sku = implode("-", array($first, $last));
would work if you want to use implode
$polish_sku = implode("-", $first, $last);
should be
$polish_sku = implode("-", array($first, $last));
Moreover you can simply take advantage of string concatenation like
$polish_sku = $first.'-'.$last
or
$polish_sku = sprintf("%s-%s", $first, $last);
$polish_sku = implode("-", $elements);
if $elements have more than two elements:
$polish_sku = implode("-", array($elements[0],$elements[1]));
Try this:
$polish_sku = implode("-", array($first, $last));
implode takes an array as the second parameter.