<?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>Agence de Développement Informatique du Nord &#187; array</title>
	<atom:link href="http://blog.adin.pro/tag/array/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.adin.pro</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Thu, 26 Dec 2019 08:54:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>PHP define constants with arrays</title>
		<link>http://blog.adin.pro/2015-01-14/php-define-constants-with-arrays/</link>
		<comments>http://blog.adin.pro/2015-01-14/php-define-constants-with-arrays/#comments</comments>
		<pubDate>Wed, 14 Jan 2015 09:30:18 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[constant]]></category>
		<category><![CDATA[define]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=445</guid>
		<description><![CDATA[<p>You need to define a constant containing an array but the code below doesn&#8217;t work ? You get an error : To define an use a constant containing an array you can simply serialize it :</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2015-01-14/php-define-constants-with-arrays/">PHP define constants with arrays</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>You need to define a constant containing an array but the code below doesn&#8217;t work ?</p>
<pre class="brush: php; title: ; notranslate">
define('FILTER_ECOLE', array('price, categorie, niveau'));
</pre>
<p>You get an error :</p>
<pre class="brush: php; title: ; notranslate">
Notice: Use of undefined constant FILTER_ECOLE - assumed 'FILTER_ECOLE'  in /home/www/adin/app/code/local/Adin/Catalog/Block/Nav/Catalog/Layer/View/Sidebar.php on line 50
</pre>
<p>To define an use a constant containing an array you can simply serialize it :</p>
<pre class="brush: php; title: ; notranslate">
#define
define('FILTER_ECOLE', serialize(array('price, categorie, niveau')));

#use
$filter = unserialize(FILTER_ECOLE);
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2015-01-14/php-define-constants-with-arrays/">PHP define constants with arrays</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2015-01-14/php-define-constants-with-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP sort array by sub value</title>
		<link>http://blog.adin.pro/2013-02-12/php-sort-array-by-sub-value/</link>
		<comments>http://blog.adin.pro/2013-02-12/php-sort-array-by-sub-value/#comments</comments>
		<pubDate>Tue, 12 Feb 2013 15:29:51 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=106</guid>
		<description><![CDATA[<p>Here my array structure : How to sort by the [sort] value inside my array ? I have to use the usort() function : Here the result : If you want to maintain the index value association, use the uasort() &#8230; <a href="http://blog.adin.pro/2013-02-12/php-sort-array-by-sub-value/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-02-12/php-sort-array-by-sub-value/">PHP sort array by sub value</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Here my array structure :</p>
<pre class="brush: php; title: ; notranslate">
Array
(
    [33] =&gt; Array
        (
            [id_site] =&gt; 33
            [datas] =&gt; Array
                (
                    [id] =&gt; 2965
                    [site_id] =&gt; 33
                    [operation_id] =&gt; 20
                    [positionnement] =&gt; 1
                )
            [statut] =&gt; Validé DM
            [sort] =&gt; 0119
        )
    [32] =&gt; Array
        (
            [id_site] =&gt; 32
            [datas] =&gt; Array
                (
                    [id] =&gt; 1929
                    [site_id] =&gt; 32
                    [operation_id] =&gt; 20
                    [positionnement] =&gt; 1
                 )
            [statut] =&gt; Validé DM
            [sort] =&gt; 0114
        )
    [34] =&gt; Array
        (
            [id_site] =&gt; 34
            [datas] =&gt; Array
                (
                    [id] =&gt; 2230
                    [site_id] =&gt; 34
                    [operation_id] =&gt; 20
                    [positionnement] =&gt; 1
                )
            [statut] =&gt; Validé DM
            [sort] =&gt; 0128
        )
)
</pre>
<p>How to sort by the [sort] value inside my array ?</p>
<p>I have to use the usort() function :</p>
<pre class="brush: php; title: ; notranslate">
function sortByCustom($a, $b) {
    return strcmp($a['sort'], $b['sort']);
}
...
usort($array, 'sortByCustom');
</pre>
<p>Here the result :</p>
<pre class="brush: php; title: ; notranslate">
Array
(
    [0] =&gt; Array
        (
            [id_site] =&gt; 32
            [datas] =&gt; Array
                (
                    [id] =&gt; 1929
                    [site_id] =&gt; 32
                    [operation_id] =&gt; 20
                    [positionnement] =&gt; 1
                 )
            [statut] =&gt; Validé DM
            [sort] =&gt; 0114
        )

    [1] =&gt; Array
        (
            [id_site] =&gt; 33
            [datas] =&gt; Array
                (
                    [id] =&gt; 2965
                    [site_id] =&gt; 33
                    [operation_id] =&gt; 20
                    [positionnement] =&gt; 1
                )
            [statut] =&gt; Validé DM
            [sort] =&gt; 0119
        )
    [2] =&gt; Array
        (
            [id_site] =&gt; 34
            [datas] =&gt; Array
                (
                    [id] =&gt; 2230
                    [site_id] =&gt; 34
                    [operation_id] =&gt; 20
                    [positionnement] =&gt; 1
                )
            [statut] =&gt; Validé DM
            [sort] =&gt; 0128
        )
)</pre>
<p>If you want to maintain the index value association, use the uasort() function</p>
<pre class="brush: php; title: ; notranslate">
uasort($array, 'sortByCustom');
</pre>
<p>Here the result :</p>
<pre class="brush: php; title: ; notranslate">
Array
(
    [32] =&gt; Array
        (
            [id_site] =&gt; 32
            [datas] =&gt; Array
                (
                    [id] =&gt; 1929
                    [site_id] =&gt; 32
                    [operation_id] =&gt; 20
                    [positionnement] =&gt; 1
                 )
            [statut] =&gt; Validé DM
            [sort] =&gt; 0114
        )

    [33] =&gt; Array
        (
            [id_site] =&gt; 33
            [datas] =&gt; Array
                (
                    [id] =&gt; 2965
                    [site_id] =&gt; 33
                    [operation_id] =&gt; 20
                    [positionnement] =&gt; 1
                )
            [statut] =&gt; Validé DM
            [sort] =&gt; 0119
        )

    [34] =&gt; Array
        (
            [id_site] =&gt; 34
            [datas] =&gt; Array
                (
                    [id] =&gt; 2230
                    [site_id] =&gt; 34
                    [operation_id] =&gt; 20
                    [positionnement] =&gt; 1
                )
            [statut] =&gt; Validé DM
            [sort] =&gt; 0128
        )
)
</pre>
<p>If you use this in a class, you have to define the sort function outside the class </p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
function sortByCustom($a, $b)
{
        return strcmp($a['sort'], $b['sort']);
}
class positionnemen {
...
</pre>
<p>for strict number comparaison, you can also use this function</p>
<pre class="brush: php; title: ; notranslate">
  function sortByCustom($a, $b)
  {
      if($a['nbr'] &gt; $b['nbr'])
      {
          return 1;
      }
      return -1;
  }
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-02-12/php-sort-array-by-sub-value/">PHP sort array by sub value</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-02-12/php-sort-array-by-sub-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
