<?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>Mukesh Chapagain&#039;s Blog &#187; array</title>
	<atom:link href="http://blog.chapagain.com.np/tag/array/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.chapagain.com.np</link>
	<description>PHP Magento jQuery SQL Wordpress Joomla Programming &#38; Tutorial</description>
	<lastBuildDate>Tue, 07 Feb 2012 00:54:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>PHP: Parse Unparse String Array</title>
		<link>http://blog.chapagain.com.np/php-parse-unparse-string-array/</link>
		<comments>http://blog.chapagain.com.np/php-parse-unparse-string-array/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 07:28:49 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=871</guid>
		<description><![CDATA[Here is a quick tip on parsing and unparsing string and array in PHP. You can parses the string into variables by using the parse_str PHP function. Using parse_str function void parse_str ( string $str [, array &#038;$arr ] ) $str = The input string. $arr = If the second parameter arr is present, variables [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/random-number-string-generation-in-php/' rel='bookmark' title='Permanent Link: Random number, string generation in PHP'>Random number, string generation in PHP</a></li>
<li><a href='http://blog.chapagain.com.np/how-to-change-the-source-code-and-modifyparse-a-website/' rel='bookmark' title='Permanent Link: How to change the source code and modify/parse a website?'>How to change the source code and modify/parse a website?</a></li>
<li><a href='http://blog.chapagain.com.np/php-generating-random-string/' rel='bookmark' title='Permanent Link: PHP: Generating Multiple Random String'>PHP: Generating Multiple Random String</a></li>
<li><a href='http://blog.chapagain.com.np/php-how-to-get-integer-or-decimal-from-a-string/' rel='bookmark' title='Permanent Link: PHP: How to get integer or decimal from a string?'>PHP: How to get integer or decimal from a string?</a></li>
<li><a href='http://blog.chapagain.com.np/php-javascript-playing-with-multi-dimensional-array/' rel='bookmark' title='Permanent Link: PHP Javascript : Playing with multi-dimensional array'>PHP Javascript : Playing with multi-dimensional array</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Here is a quick tip on parsing and unparsing string and array in PHP.</p>
<p>You can parses the string into variables by using the <strong>parse_str</strong> PHP function.</p>
<p><strong>Using parse_str function</strong></p>
<p><span id="more-871"></span></p>
<p><strong>void parse_str  (  string $str  [,  array &#038;$arr  ] )</strong></p>
<p>$str = The input string.<br />
$arr = If the second parameter arr is present, variables are stored in this variable as array elements instead.</p>
<p><strong>Using single parameter</strong></p>
<pre class="brush: php; title: ; notranslate">
$str = &quot;first=value&amp;arr[]=foo+bar&amp;arr[]=baz&quot;;
parse_str($str, $data);
echo $first;  // value
echo $arr[0]; // foo bar
echo $arr[1]; // baz
</pre>
<p><strong>Using the second parameter</strong></p>
<pre class="brush: php; title: ; notranslate">
$str = &quot;first=value&amp;arr[]=foo+bar&amp;arr[]=baz&quot;;
parse_str($str, $data);
echo &quot;&lt;pre&gt;&quot;; print_r($data); echo &quot;&lt;/pre&gt;&quot;;
</pre>
<p>The output will be:-</p>
<pre class="brush: php; title: ; notranslate">
Array
(
    [first] =&gt; value
    [arr] =&gt; Array
        (
            [0] =&gt; foo bar
            [1] =&gt; baz
        )

)
</pre>
<p>You can unparse any array into string using the <strong>http_build_query</strong> function. This generates a URL-encoded query string from the associative (or indexed) array provided. </p>
<pre class="brush: php; title: ; notranslate">
$data = array('foo'=&gt;'bar',
              'baz'=&gt;'boom',
              'cow'=&gt;'milk',
              'php'=&gt;'hypertext processor');

echo http_build_query($data); // foo=bar&amp;baz=boom&amp;cow=milk&amp;php=hypertext+processor
echo http_build_query($data, '', '&amp;amp;'); // foo=bar&amp;amp;baz=boom&amp;amp;cow=milk&amp;amp;php=hypertext+processor
</pre>
<p>Hope this helps. Thanks.</p>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=871&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/random-number-string-generation-in-php/' rel='bookmark' title='Permanent Link: Random number, string generation in PHP'>Random number, string generation in PHP</a></li>
<li><a href='http://blog.chapagain.com.np/how-to-change-the-source-code-and-modifyparse-a-website/' rel='bookmark' title='Permanent Link: How to change the source code and modify/parse a website?'>How to change the source code and modify/parse a website?</a></li>
<li><a href='http://blog.chapagain.com.np/php-generating-random-string/' rel='bookmark' title='Permanent Link: PHP: Generating Multiple Random String'>PHP: Generating Multiple Random String</a></li>
<li><a href='http://blog.chapagain.com.np/php-how-to-get-integer-or-decimal-from-a-string/' rel='bookmark' title='Permanent Link: PHP: How to get integer or decimal from a string?'>PHP: How to get integer or decimal from a string?</a></li>
<li><a href='http://blog.chapagain.com.np/php-javascript-playing-with-multi-dimensional-array/' rel='bookmark' title='Permanent Link: PHP Javascript : Playing with multi-dimensional array'>PHP Javascript : Playing with multi-dimensional array</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/php-parse-unparse-string-array/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery: Print array and object</title>
		<link>http://blog.chapagain.com.np/jquery-print-array-and-object/</link>
		<comments>http://blog.chapagain.com.np/jquery-print-array-and-object/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 04:53:16 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[print]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=518</guid>
		<description><![CDATA[It&#8217;s very easy to print array and object with jQuery. You can do it with jQuery.each() function. The jQuery.each() function can be used to iterate over any collection, whether it is a map (JavaScript object) or an array. Here is the javascript code to print array or object: Here, arr is a numeric array. Its [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/print_r-in-javascript/' rel='bookmark' title='Permanent Link: print_r in Javascript'>print_r in Javascript</a></li>
<li><a href='http://blog.chapagain.com.np/jquery-grey-out-background-and-preview-image-as-popup/' rel='bookmark' title='Permanent Link: jQuery: Grey out background and preview image as popup'>jQuery: Grey out background and preview image as popup</a></li>
<li><a href='http://blog.chapagain.com.np/magento-jquery-how-to-use-them-together/' rel='bookmark' title='Permanent Link: Magento jQuery: How to use them together?'>Magento jQuery: How to use them together?</a></li>
<li><a href='http://blog.chapagain.com.np/jquery-how-to-replace-string-div-content-and-image-src/' rel='bookmark' title='Permanent Link: jQuery: How to replace string, div content and image src?'>jQuery: How to replace string, div content and image src?</a></li>
<li><a href='http://blog.chapagain.com.np/using-jquery-ajax-populate-selection-list/' rel='bookmark' title='Permanent Link: Using jQuery &#038; AJAX: Populate Selection List'>Using jQuery &#038; AJAX: Populate Selection List</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s very easy to print array and object with jQuery. You can do it with jQuery.each() function. The jQuery.each() function can be used to iterate over any collection, whether it is a map (JavaScript object) or an array.</p>
<p>Here is the javascript code to print array or object:</p>
<pre class="brush: jscript; title: ; notranslate">
jQuery(document).ready(function(){
	var arr = [ &quot;earth&quot;, &quot;mars&quot;, &quot;jupiter&quot;, &quot;saturn&quot;, &quot;venus&quot; ];
	var obj = { one:&quot;earth&quot;, two:&quot;mars&quot;, three:&quot;jupiter&quot;, four:&quot;saturn&quot;, five:&quot;venus&quot; };

	jQuery.each(arr, function(i, val) {
	  $(&quot;#arrData&quot;).append(i + &quot; : &quot; + val + &quot;&lt;br/&gt;&quot;);
	});

	jQuery.each(obj, function(i, val) {
	  $(&quot;#objData&quot;).append(i + &quot; =&gt; &quot; + val + &quot;&lt;br/&gt;&quot;);
	});
});
</pre>
<p>Here, <em>arr</em> is a numeric array. Its key and value are printed in the div with id <em>arrData</em>. Similarly, <em>obj</em> is an associative array or object. Its key and value are printed in the div with id <em>objData</em>. </p>
<p><span id="more-518"></span></p>
<p>Here is the full source code:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;jQuery: Print array and object&lt;/title&gt;
&lt;script src=&quot;jquery-1.4.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	jQuery(document).ready(function(){
		var arr = [ &quot;earth&quot;, &quot;mars&quot;, &quot;jupiter&quot;, &quot;saturn&quot;, &quot;venus&quot; ];
		var obj = { one:&quot;earth&quot;, two:&quot;mars&quot;, three:&quot;jupiter&quot;, four:&quot;saturn&quot;, five:&quot;venus&quot; };

		jQuery.each(arr, function(i, val) {
		  $(&quot;#arrData&quot;).append(i + &quot; : &quot; + val + &quot;&lt;br/&gt;&quot;);
		});

		jQuery.each(obj, function(i, val) {
		  $(&quot;#objData&quot;).append(i + &quot; =&gt; &quot; + val + &quot;&lt;br/&gt;&quot;);
		});
	});
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;arrData&quot;&gt;
&lt;strong&gt;Array&lt;/strong&gt;&lt;br/&gt;

&lt;/div&gt;

&lt;div id=&quot;objData&quot;&gt;
&lt;strong&gt;Object&lt;/strong&gt;&lt;br/&gt;

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Cheers,</p>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=518&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/print_r-in-javascript/' rel='bookmark' title='Permanent Link: print_r in Javascript'>print_r in Javascript</a></li>
<li><a href='http://blog.chapagain.com.np/jquery-grey-out-background-and-preview-image-as-popup/' rel='bookmark' title='Permanent Link: jQuery: Grey out background and preview image as popup'>jQuery: Grey out background and preview image as popup</a></li>
<li><a href='http://blog.chapagain.com.np/magento-jquery-how-to-use-them-together/' rel='bookmark' title='Permanent Link: Magento jQuery: How to use them together?'>Magento jQuery: How to use them together?</a></li>
<li><a href='http://blog.chapagain.com.np/jquery-how-to-replace-string-div-content-and-image-src/' rel='bookmark' title='Permanent Link: jQuery: How to replace string, div content and image src?'>jQuery: How to replace string, div content and image src?</a></li>
<li><a href='http://blog.chapagain.com.np/using-jquery-ajax-populate-selection-list/' rel='bookmark' title='Permanent Link: Using jQuery &#038; AJAX: Populate Selection List'>Using jQuery &#038; AJAX: Populate Selection List</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/jquery-print-array-and-object/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>print_r in Javascript</title>
		<link>http://blog.chapagain.com.np/print_r-in-javascript/</link>
		<comments>http://blog.chapagain.com.np/print_r-in-javascript/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 07:45:02 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[print]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=491</guid>
		<description><![CDATA[It&#8217;s a real headache when you have to work on objects and arrays in Javascript. It would be lot easier to detect elements of the Javascript objects/arrays if we have print_r function in Javascript as we have in PHP. I googled the web and have found a very efficient print_r Javascript function. This has helped [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/javascript-showhide-html-elements/' rel='bookmark' title='Permanent Link: Javascript: Show/Hide HTML elements'>Javascript: Show/Hide HTML elements</a></li>
<li><a href='http://blog.chapagain.com.np/website-statistic-user-information-in-javascript/' rel='bookmark' title='Permanent Link: Website statistic (User Information) in Javascript'>Website statistic (User Information) in Javascript</a></li>
<li><a href='http://blog.chapagain.com.np/javascript-add-remove-html-elements/' rel='bookmark' title='Permanent Link: Javascript: Add Remove HTML elements'>Javascript: Add Remove HTML elements</a></li>
<li><a href='http://blog.chapagain.com.np/javascript-how-to-submit-form-and-change-form-action/' rel='bookmark' title='Permanent Link: Javascript: How to Submit form and Change form action?'>Javascript: How to Submit form and Change form action?</a></li>
<li><a href='http://blog.chapagain.com.np/php-javascript-playing-with-multi-dimensional-array/' rel='bookmark' title='Permanent Link: PHP Javascript : Playing with multi-dimensional array'>PHP Javascript : Playing with multi-dimensional array</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a real headache when you have to work on objects and arrays in Javascript. It would be lot easier to detect elements of the Javascript objects/arrays if we have print_r function in Javascript as we have in PHP.</p>
<p>I googled the web and have found a very efficient print_r Javascript function. This has helped me a lot in my projects. Here is the code:-</p>
<p><span id="more-491"></span></p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
	function print_r(theObj){
	   if(theObj.constructor == Array || theObj.constructor == Object){
		  document.write(&quot;&lt;ul&gt;&quot;)
		  for(var p in theObj){
			 if(theObj[p].constructor == Array || theObj[p].constructor == Object){
				document.write(&quot;&lt;li&gt;[&quot;+p+&quot;] =&gt; &quot;+typeof(theObj)+&quot;&lt;/li&gt;&quot;);
				document.write(&quot;&lt;ul&gt;&quot;)
				print_r(theObj[p]);
				document.write(&quot;&lt;/ul&gt;&quot;)
			 } else {
				document.write(&quot;&lt;li&gt;[&quot;+p+&quot;] =&gt; &quot;+theObj[p]+&quot;&lt;/li&gt;&quot;);
			 }
		  }
		  document.write(&quot;&lt;/ul&gt;&quot;)
	   }
	}
&lt;/script&gt;
</pre>
<p><strong>USING PRINT_R</strong></p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
print_r(JAVACRIPT_ARRAY_OR_OBJECT);
&lt;/script&gt;
</pre>
<p><em>Source: http://www.brandnewbox.co.uk/articles/details/a_print_r_equivalent_for_javascript/</em></p>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=491&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/javascript-showhide-html-elements/' rel='bookmark' title='Permanent Link: Javascript: Show/Hide HTML elements'>Javascript: Show/Hide HTML elements</a></li>
<li><a href='http://blog.chapagain.com.np/website-statistic-user-information-in-javascript/' rel='bookmark' title='Permanent Link: Website statistic (User Information) in Javascript'>Website statistic (User Information) in Javascript</a></li>
<li><a href='http://blog.chapagain.com.np/javascript-add-remove-html-elements/' rel='bookmark' title='Permanent Link: Javascript: Add Remove HTML elements'>Javascript: Add Remove HTML elements</a></li>
<li><a href='http://blog.chapagain.com.np/javascript-how-to-submit-form-and-change-form-action/' rel='bookmark' title='Permanent Link: Javascript: How to Submit form and Change form action?'>Javascript: How to Submit form and Change form action?</a></li>
<li><a href='http://blog.chapagain.com.np/php-javascript-playing-with-multi-dimensional-array/' rel='bookmark' title='Permanent Link: PHP Javascript : Playing with multi-dimensional array'>PHP Javascript : Playing with multi-dimensional array</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/print_r-in-javascript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PHP Javascript : Playing with multi-dimensional array</title>
		<link>http://blog.chapagain.com.np/php-javascript-playing-with-multi-dimensional-array/</link>
		<comments>http://blog.chapagain.com.np/php-javascript-playing-with-multi-dimensional-array/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 05:27:15 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[for loop]]></category>
		<category><![CDATA[multi-dimensional]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/?p=220</guid>
		<description><![CDATA[I had to work on multi-dimensional array with javascript and php. I had a multi-dimensional array in php. I had to load it into javascript array and then populate the html selection list. The challenge for me was to create multi-dimensional array in javascript and populate selection list with for loop in javascript. Here is [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/php-parse-unparse-string-array/' rel='bookmark' title='Permanent Link: PHP: Parse Unparse String Array'>PHP: Parse Unparse String Array</a></li>
<li><a href='http://blog.chapagain.com.np/print_r-in-javascript/' rel='bookmark' title='Permanent Link: print_r in Javascript'>print_r in Javascript</a></li>
<li><a href='http://blog.chapagain.com.np/go-back-link-in-javascript/' rel='bookmark' title='Permanent Link: Go back link in Javascript'>Go back link in Javascript</a></li>
<li><a href='http://blog.chapagain.com.np/jquery-print-array-and-object/' rel='bookmark' title='Permanent Link: jQuery: Print array and object'>jQuery: Print array and object</a></li>
<li><a href='http://blog.chapagain.com.np/displaying-date-and-time/' rel='bookmark' title='Permanent Link: Displaying date and time'>Displaying date and time</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I had to work on multi-dimensional array with javascript and php. I had a multi-dimensional array in php. I had to load it into javascript array and then populate the html selection list.</p>
<p>The challenge for me was to create multi-dimensional array in javascript and populate selection list with for loop in javascript.</p>
<p><span id="more-220"></span></p>
<p>Here is the full code containing php array, creating javascript array, using for loop in javascript to populate selection list in onclick event.</p>
<p>Given php array:-</p>
<pre class="brush: php; title: ; notranslate">

&lt;?php
$items = array(
'subject'=&gt; array(
'easy' =&gt; array('music','history'),
'difficult' =&gt; array('maths','science')
),
'sports'=&gt;array(
'easy' =&gt; array('cricket'),
'difficult' =&gt; array('football','basketball')
)
);

$keyName = array();
?&gt;
</pre>
<p>Creating array in javascript with php array:-</p>
<pre class="brush: php; title: ; notranslate">

var itemData = new Array();
	&lt;?php
	foreach($items as $key=&gt;$value)
	{
		foreach($value as $k=&gt;$v)
		{
			$v = implode(&quot;,&quot;,$v);

			if(!in_array($key,$keyName))
			{
				?&gt;
				itemData['&lt;?php echo $key; ?&gt;'] = new Array();
				&lt;?php
			}
			?&gt;
				itemData['&lt;?php echo $key; ?&gt;']['&lt;?php echo $k; ?&gt;'] = new Array('&lt;?php echo str_replace(&quot;,&quot;,&quot;','&quot;,trim($v)); ?&gt;');
		&lt;?php
			$keyName[] = $key;
		}
	}
	?&gt;
</pre>
<p>Populating selection list with javascript for loop:-</p>
<pre class="brush: jscript; title: ; notranslate">
for (i=0; i&lt;itemData['subject']['easy'].length; i++)
{
	subjectEasy.options[subjectEasy.options.length]=new Option(itemData['subject']['easy'][i],itemData['subject']['easy'][i])
}
</pre>
<p><a title="PHP Javascript Multi-dimensional array" href="http://chapagain.googlecode.com/files/multi_js.php" target="_blank">Download Full Source Code</a></p>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=220&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/php-parse-unparse-string-array/' rel='bookmark' title='Permanent Link: PHP: Parse Unparse String Array'>PHP: Parse Unparse String Array</a></li>
<li><a href='http://blog.chapagain.com.np/print_r-in-javascript/' rel='bookmark' title='Permanent Link: print_r in Javascript'>print_r in Javascript</a></li>
<li><a href='http://blog.chapagain.com.np/go-back-link-in-javascript/' rel='bookmark' title='Permanent Link: Go back link in Javascript'>Go back link in Javascript</a></li>
<li><a href='http://blog.chapagain.com.np/jquery-print-array-and-object/' rel='bookmark' title='Permanent Link: jQuery: Print array and object'>jQuery: Print array and object</a></li>
<li><a href='http://blog.chapagain.com.np/displaying-date-and-time/' rel='bookmark' title='Permanent Link: Displaying date and time'>Displaying date and time</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/php-javascript-playing-with-multi-dimensional-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun with strings in PHP (Part 1)</title>
		<link>http://blog.chapagain.com.np/fun-with-strings-in-php-part-1/</link>
		<comments>http://blog.chapagain.com.np/fun-with-strings-in-php-part-1/#comments</comments>
		<pubDate>Sun, 09 Dec 2007 04:48:39 +0000</pubDate>
		<dc:creator>Mukesh</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[concatenate]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://blog.chapagain.com.np/2007/12/09/fun-with-strings-in-php-part-1/</guid>
		<description><![CDATA[Problem: Concatenate and fetch data from two fields of database and then break it again. Solution: Posted below. The description is included in the code. You have to make a mysql database. The database part is as under: PHP code below: I have not used any loop (for, while, foreach, etc.) here to make the [...]


<strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/session-handling-in-php/' rel='bookmark' title='Permanent Link: Session Handling in PHP'>Session Handling in PHP</a></li>
<li><a href='http://blog.chapagain.com.np/page-refresh-in-php/' rel='bookmark' title='Permanent Link: Page refresh in PHP'>Page refresh in PHP</a></li>
<li><a href='http://blog.chapagain.com.np/how-to-get-working-site-path-and-directory-name-in-php/' rel='bookmark' title='Permanent Link: How to get working site path and directory name in php?'>How to get working site path and directory name in php?</a></li>
<li><a href='http://blog.chapagain.com.np/regular-expression-check-validation-in-php/' rel='bookmark' title='Permanent Link: Regular Expression check, Validation in PHP'>Regular Expression check, Validation in PHP</a></li>
<li><a href='http://blog.chapagain.com.np/file-upload-in-php-simplified/' rel='bookmark' title='Permanent Link: File Upload in PHP :: Simplified'>File Upload in PHP :: Simplified</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>Concatenate and fetch data from two fields of database and then break it again.</p>
<p><strong>Solution:</strong></p>
<p><span id="more-36"></span></p>
<p>Posted below.</p>
<p>The description is included in the code.</p>
<p>You have to make a mysql database. The database part is as under:</p>
<pre class="brush: sql; title: ; notranslate">
create database test;

use test;

create table user(id int(9) not null auto_increment, first_name varchar(20), last_name varchar(20), primary key(id));

insert into user(first_name, last_name) values (&quot;mukesh&quot;,&quot;chapagain&quot;);
</pre>
<p>PHP code below:</p>
<p>I have not used any loop (for, while, foreach, etc.)  here to make the code simple. :-)</p>
<pre class="brush: php; title: ; notranslate">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Fun with strings&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;?php

// in my configuration, i am running mysql in localhost, my database username is 'root' and i don't have any database password
// i have a table called 'user' in the database 'test'

// connecting to the database server
mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;);

// connecting to the database
mysql_select_db(&quot;test&quot;);

// selecting data from table named 'user' where id = 1
$result = mysql_query(&quot;select concat(first_name,',',last_name) as name from user where id = '1'&quot;);

// fetching the result and assigning it to certain variables
while ($row = mysql_fetch_assoc($result))
{
$name = $row['name'];
echo &quot;$name &lt;br/&gt;&quot;; // you will get the result as first_name,last_name
}
$newName = explode(&quot;,&quot;,$name); // this will make an array with each name as values

//print_r($newName);

// print the first name as
echo &quot;First Name: &quot; . $newName[0] . &quot;&lt;br/&gt;&quot;;

// print the second name as
echo &quot;Second Name: &quot; . $newName[1] . &quot;&lt;br/&gt;&quot;;

// you can find about how many elements/items are there with the commas
$count = count($newName);
echo &quot;Count: $count &lt;br/&gt;&quot;;

// there is a function called 'implode' which will join array elements with a string
$newNameTwo = implode(&quot; &quot;,$newName); // this will print the names with spaces in between... before the names were separated with comma
echo &quot;$newNameTwo &lt;br/&gt;&quot;;

?&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Happy PHPing!</p>
<hr /><small>Copyright &copy; 2011<br /> This feed is for personal, non-commercial use only. <br /> The use of this feed on other websites breaches copyright. If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright. (Digital Fingerprint:<br /> )</small><img src="http://blog.chapagain.com.np/?ak_action=api_record_view&id=36&type=feed" alt="" />

<p><strong>Related posts:</strong><ol><li><a href='http://blog.chapagain.com.np/session-handling-in-php/' rel='bookmark' title='Permanent Link: Session Handling in PHP'>Session Handling in PHP</a></li>
<li><a href='http://blog.chapagain.com.np/page-refresh-in-php/' rel='bookmark' title='Permanent Link: Page refresh in PHP'>Page refresh in PHP</a></li>
<li><a href='http://blog.chapagain.com.np/how-to-get-working-site-path-and-directory-name-in-php/' rel='bookmark' title='Permanent Link: How to get working site path and directory name in php?'>How to get working site path and directory name in php?</a></li>
<li><a href='http://blog.chapagain.com.np/regular-expression-check-validation-in-php/' rel='bookmark' title='Permanent Link: Regular Expression check, Validation in PHP'>Regular Expression check, Validation in PHP</a></li>
<li><a href='http://blog.chapagain.com.np/file-upload-in-php-simplified/' rel='bookmark' title='Permanent Link: File Upload in PHP :: Simplified'>File Upload in PHP :: Simplified</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chapagain.com.np/fun-with-strings-in-php-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
