<?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>Haitham Gasim &#187; php multidimensional array reorder</title>
	<atom:link href="http://www.haithamgasim.com/tag/php-multidimensional-array-reorder/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.haithamgasim.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 23 Apr 2011 18:54:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHP Multidimensional Arrays Tip</title>
		<link>http://www.haithamgasim.com/2009/12/27/php-multidimensional-arrays-tip/</link>
		<comments>http://www.haithamgasim.com/2009/12/27/php-multidimensional-arrays-tip/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 17:12:56 +0000</pubDate>
		<dc:creator>Haitham</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[php multidimensional array reorder]]></category>

		<guid isPermaLink="false">http://www.haithamgasim.com/?p=67</guid>
		<description><![CDATA[I hope this will help someone someday for it took me a minute to figure out.  I am working on a web application that requires the addition of datasets that can be unique or similar.  Each set is to be displayed on a unique row and each row will display data that is being pulled [...]]]></description>
			<content:encoded><![CDATA[<p>I hope this will help someone someday for it took me a minute to figure out.  I am working on a web application that requires the addition of datasets that can be unique or similar.  Each set is to be displayed on a unique row and each row will display data that is being pulled from a DB, a grid framework per se.  Users of the system will be able to alter the contents of the rows and rearrange the order of the rows on the fly before they can save them back to the DB.</p>
<p>I stored everything in multidimensional arrays and when adding new sets or new rows with keys that already exist in the sequence hindered the correct reordering of them.  Example:</p>
<p>The grid is comprised of</p>
<p>$set1[$key1][1]= $array1;</p>
<p>$set2[$key2][1] = $array2;</p>
<p>with $key1 and $key2 being numerical.</p>
<p>Adding a new row of $set1[$key1] at the end of the grid, i.e.,</p>
<p>$set1[$Key1][2] needed to generate the following order:</p>
<p>$set1[$key1][1]= $array1;</p>
<p>$set2[$key2][1] = $array2;</p>
<p>$set1[$Key1][2] = $array1;</p>
<p>However, no matter what I did to populate the arrays sequentially, the order reverted to:</p>
<p>$set1[$key1][1]= $array1;</p>
<p>$set1[$Key1][2] = $array1;</p>
<p>$set2[$key2][1] = $array2;</p>
<p>The easiest fix I could find (I know several others are out there) to achieve the goal was change the keys from numerical to strings.  I did that by combining them and separating them by a glue character (-, @, _, etc.).  The result was:</p>
<p>$set1[$key1_1]= $array1;</p>
<p>$set2[$key2_1] = $array2;</p>
<p>$set1[$Key1_2] = $array1;</p>
<p>To process the data afterward, I split the keys into an array by taking into the account the glue character that I used.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.haithamgasim.com/2009/12/27/php-multidimensional-arrays-tip/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

