-3

Suppose I have a string "stackoverflowdescription" and i have converted into array using str_split, now a want to put space in between each word say "stack over flow description" using array and string functions.

Ex: stackoverflowdescription --> noitpircsedwolfrevokcats --> noitpircsed wolf revo kcats --> stack over flow description

Frnd
  • 1
  • 1
  • [`join`](http://php.net/join)? – deceze Mar 06 '13 at 06:44
  • 2
    And who will decides that `over` & `flow` is different word & not `overflow` ? :p – Rikesh Mar 06 '13 at 06:44
  • Why are you trying to do this ? Describe the complete scenario. – SilentAssassin Mar 06 '13 at 07:04
  • @SilentAssassin: Just started learning PHP, so playing the string and array functions. – Frnd Mar 06 '13 at 09:11
  • I want to first convert the string to array then reverse the array, then put space at the defined index and then print the output in original order with space. Ex: stackoverflowdescription --> noitpircsedwolfrevokcats --> noitpircsed wolf revo kcats --> stack over flow description – Frnd Mar 06 '13 at 09:41

1 Answers1

2
<?php
$output = implode(" ", $yourArrayOfWords);
?>
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
  • 1
    Beat me to the punch. This is the same as @deceze `join()`. – Sam Mar 06 '13 at 06:46
  • Except that @deceze put it in the comment and not the answer. – dfsq Mar 06 '13 at 06:47
  • Hehe :) yeah `join` is an alias of `implode` – Hanky Panky Mar 06 '13 at 06:47
  • I want to first convert the string to array then reverse the array, then put space at the defined index and then print the output in original order with space. Ex: stackoverflowdescription --> noitpircsedwolfrevokcats --> noitpircsed wolf revo kcats --> stack over flow description – Frnd Mar 06 '13 at 09:41