Jump to content

[SOLVED] split() into array


php_b34st

Recommended Posts

I have the following code:

 

<script type="text/javascript">

var str="code name club price";

document.write(str.split(" ",1) + "<br />");
document.write(str.split(" ",2) + "<br />");
document.write(str.split(" ",3) + "<br />");
document.write(str.split(" ",4));
</script>

Its not quite how i wanted it to output so I was wondering how i would put it into an array instead,at the moment it outputs like this:

 

code
code,name
code,name,club
code,name,club,price

 

when I only wanted:

 

code
name
club
price

 

is there a way to put them in an array so that i can use each element seperately?

Link to comment
Share on other sites

I do not need to add a line break I just showed that as an example, I need to be able to use each element seperately so that I can use the data in other functions which is why i thought an array would be suitable?

 

There will be 11 different elements for code name club price I need to display these and add all the price elements to make a total price also i need to make sure the same club has not been used more than twice and the same name has not been used more than once. I have made the php script which handles this I just need javascript to pass it onto the php side.

 

thanks again for any help

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.