<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>e r e b o s . n e t &#187; php javascript</title>
	<atom:link href="http://www.erebos.net/tag/php-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.erebos.net</link>
	<description></description>
	<lastBuildDate>Tue, 12 Jan 2010 22:56:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Passing Javascript Arrays to PHP</title>
		<link>http://www.erebos.net/2009/04/passing-javascript-arrays-to-php/</link>
		<comments>http://www.erebos.net/2009/04/passing-javascript-arrays-to-php/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 01:40:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[php javascript]]></category>

		<guid isPermaLink="false">http://www.erebos.net/?p=94</guid>
		<description><![CDATA[Needed to pass a simple Javascript array to a PHP script for some back end processing.   Here&#8217;s a quick and dirty way of doing so by &#8217;serializing&#8217;  the javascript array as a string to send along in your request, and then splitting this string into tokens to create a PHP array.
Javascript: (using [...]]]></description>
			<content:encoded><![CDATA[<p>Needed to pass a simple Javascript array to a PHP script for some back end processing.   Here&#8217;s a quick and dirty way of doing so by &#8217;serializing&#8217;  the javascript array as a string to send along in your request, and then splitting this string into tokens to create a PHP array.</p>
<p>Javascript: <em>(using <a href="http://jquery.com/">jquery</a> javascript library)</em><br />
<code><br />
	var selections = new Array;<br />
        var userSelections;<br />
	$('#multipleSelection :selected').each(function(i, selected) {<br />
	              selections[i] = $(selected).val();<br />
          });<br />
	userSelections = selections.join(",");<br />
</code></p>
<p>In the PHP script, it&#8217;s just a matter of processing the individual elements of the array.  Depending on how you sent the ajax request (POST/GET).</p>
<p>PHP Example:<br />
<code><br />
$selectionsArray = explode(',',$_GET['userSelections']);</p>
<p>foreach($selectedArray as $index=>$value) {<br />
  echo $index ." = ".$value;<br />
}<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.erebos.net/2009/04/passing-javascript-arrays-to-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
