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
https://forums.phpfreaks.com/topic/121014-solved-split-into-array/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.