<?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>devexp &#187; array</title>
	<atom:link href="http://www.devexp.eu/tag/array/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devexp.eu</link>
	<description>DEVelopment EXPerience, shared with the world!</description>
	<lastBuildDate>Fri, 28 Oct 2011 12:07:45 +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>Arrays or objects in PHP?</title>
		<link>http://www.devexp.eu/2008/09/25/arrays-or-objects-in-php/</link>
		<comments>http://www.devexp.eu/2008/09/25/arrays-or-objects-in-php/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 13:50:14 +0000</pubDate>
		<dc:creator>van Rumste Kenneth</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[object]]></category>

		<guid isPermaLink="false">http://blog.mg-x.eu/?p=101</guid>
		<description><![CDATA[I assumed until a couple of days ago that objects are way better then arrays, but let’s take a closer look into that. As objects are an instance of a class you can always know what type of data is &#8230; <a href="http://www.devexp.eu/2008/09/25/arrays-or-objects-in-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>I assumed until a couple of days ago that objects are way better then arrays, but let’s take a closer look into that.</p>
<p>As objects are an instance of a class you can always know what type of data is inserted in the object, when trying this in an array you quickly get in to problems, for example:</p>
<pre class="brush: php; title: ; notranslate">$testcase = array();
$testcase[&quot;Name&quot;] = &quot;testcase&quot;;
$testcase[&quot;value&quot;] = 20;</pre>
<p>When doing this in objects, you can split it up very easy like so:</p>
<pre class="brush: php; title: ; notranslate">$testcase = new testcaseObject();
$testcase-&gt;setName(&quot;testcase&quot;);
$testcase-&gt;setValue(20);</pre>
<p>I guess you see my point….</p>
<p>When using huge amount of data though, arrays seem to have the upper hand in memory usage so that can count as an advantage.</p>
<p>When we create a query to get some data from a database that returns us multiple rows, the best thing you can do is make an array of objects. Like this:</p>
<pre class="brush: php; title: ; notranslate">while( statement ) {

$id = $row-&gt;categoryId;

// If category doesn't exist, we create him, else do nothing
if (!isset($category[$id])) {
$category[$id] = new testcaseCategory ();
$category[$id]-&gt;setId($id);
$category[$id]-&gt;setName($queryrow[categoryName]);
}

// Create testcaseObject
$testcase = new testcaseObject();
$testcase-&gt;setId($queryrow[id]);
$testcase-&gt;setValue($queryrow[name]);

// Add testcaseObject to testcaseCategory.
$category[$id]-&gt;addTestCaseObject($testcase);

}</pre>
<p>Have fun with it.</p>
<div class="shr-publisher-101"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2008/09/25/arrays-or-objects-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

