Jump to content

Problems with explode and array..


Gazan

Recommended Posts

My question is very simple, however i cant seem to figure it out..

How do i explode a string and store each exploded word into an array? So the array will hold a key value for each word in the string.

 

Thanks in advantage

Link to comment
Share on other sites

I just have.

 

That is all the code you need.

 

I'll break it down a little more...

$arrWords=explode(' ',$str);

INPUT

' ' ... This is what we're using as the split point - in this case, a space

$str ... a string containing the words we want to split

 

OUTPUT

$arrWords ... an array

 

You can output the words using a simple loop:

foreach ($arrWords as $key => $word) {
  echo $key.' = '.$word.'<br />';
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.