0

I want to use the content of my javascript array in php. i need to add up all content in different groups and put them in a database. my php is better then javascript (dont realy know anyting about it).

my array content is:

["I", "S", "C", "D", "I", "D", "C", "S", "I", "C", "D", "S", "C", "D", "S", "I", "D", "C", "I", "S", "C", "S", "I", "D", "S", "C", "D", "I", "D", "S", "C", "I", "D", "I", "S", "C", "S", "D", "C", "I"]

dont know if you need it but its there.

Is it possible to content to php so i can use it there? Is it even possible becouse php is server and javascript is client.

i heared something about json but cant figure it out.

EDIT

i want to give all results a value. the first item in the array gets '4', the second item '3', third item '2' and fourth item '1', then again, so fifth item '4' sixth item '3' etc...

so u get:

"I" = 4, "S"=3, "C"=2, etc..

then i want to count up all the I's, C's, D's and S's. and put the results in a database.

thomagron
  • 101
  • 2
  • 12
  • You can use JS with PHP but I don't quite understand what you want to send to server. – Gynteniuxas Sep 02 '16 at 13:35
  • 1
    The utilities you need are in JS JSON.parse() and JSON.stringify() and in PHP it is json_decode and json_encode. However it is hard to tell how you need to wire those together in your case, because we are missing your motiviation behind your question. – yankee Sep 02 '16 at 13:36
  • http://stackoverflow.com/questions/5035547/pass-javascript-array-php – Callan Heard Sep 02 '16 at 13:37
  • made an edit to descibe a bit better – thomagron Sep 02 '16 at 13:39

1 Answers1

1

Actually this is not a clean way but yes its possible...

1)first you must parse javascript array

2)pass it to php with a ajax request

3)do the process and return the results

this is my sample:

        javaparsedArray = JSON.stringify(javaScriptArray);
        $.ajax({
            type: "POST",
            url: 'php.php',
            data:"action=parsArray&value="+javaparsedArray ,
            cache:'false',
            dataType:'json',
            beforeSend :function(){},
            complete :function(){},
            success: function(res){
                console.log(res);
            }
        });
peiman F.
  • 1,648
  • 1
  • 19
  • 42