0

I have a string.

$string = "this is my string";

So I want to explode it.

$explode = explode(' ', $string);

Now I want to know if it's possible to insert each word into an array so I can get this.

$array = array('this', 'is', 'my', 'string');
7
  • 5
    the $explode is the array similar to $array. The explode function already did it. Commented May 5, 2016 at 18:00
  • 5
    That is exactly what you have in $explode, what is the problem?! Commented May 5, 2016 at 18:01
  • 1
    With explode() you already have desired array ( $array = $explode ) Commented May 5, 2016 at 18:02
  • Thanks very much Frayne Commented May 5, 2016 at 18:02
  • 1
    You can always use var_dump($my_var) ou print_r($my_var) to see what is in your variable. Commented May 5, 2016 at 18:11

2 Answers 2

1
$array = array();
$string = "this is my string";
$explode = explode(' ', $string);

for ($i=0; $i<count($explode); $i++) {
    array_push($array, $explode[$i]);
}
print_r ($array);
Sign up to request clarification or add additional context in comments.

Comments

0

Just like Frayne Konok said, the $explode is the array similar to $array. The explode function already did it.

Comments

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.