<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problema cambio chiavi in array.]]></title><description><![CDATA[<p dir="auto">Ciao a tutti ragazzi!</p>
<p dir="auto">Avrei un problema: vorrei cambiare le chiavi di un'array in relazione ai valori di un altro array.</p>
<p dir="auto">Array 1: array( [4] =&gt; 5000, [6] =&gt; 3000, [7] =&gt; 2000, [9] =&gt; 1000)<br />
Array 2: array (     <strong>[0]</strong> =&gt; Array         (             [0] =&gt; 5000             [1] =&gt; xxx [2] =&gt; xxx             [3] =&gt; xxx         )      <strong>[1]</strong> =&gt; Array         (             [0] =&gt; 3000             [1] =&gt; xxx             [2] =&gt; xxx             [3] =&gt; xxx         )      <strong>[2]</strong> =&gt; Array         (             [0] =&gt; 2000             [1] =&gt; xxx             [2] =&gt; xxx             [3] =&gt; xxx         )      <strong>[3]</strong> =&gt; Array         (             [0] =&gt; 1000             [1] =&gt; xxx             [2] =&gt; xxx             [3] =&gt; xxx         )  )</p>
<p dir="auto">Vorrei fare in modo che le chiavi del secondo array vengano cambiate in modo che risultino uguali a quelle del primo array.</p>
<p dir="auto"><strong>[0]</strong> dovrebbe diventare [4], <strong>[1]</strong> dovrebbe diventare [6] e così via.</p>
<p dir="auto">Grazie in anticipo.</p>
]]></description><link>https://dev.connect.gt/topic/162487/problema-cambio-chiavi-in-array</link><generator>RSS for Node</generator><lastBuildDate>Wed, 25 Nov 2026 13:12:03 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/162487.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 07 Dec 2011 09:00:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problema cambio chiavi in array. on Wed, 07 Dec 2011 11:21:36 GMT]]></title><description><![CDATA[<p dir="auto">Mi rispondo da solo <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f604.png?v=bb61372b9dc" class="not-responsive emoji emoji-android emoji--smile" style="height:1.4em;width:auto;vertical-align:middle" title=":D" alt="😄" /> Così magari sarò d'aiuto a qualcun'altro nella mia stessa situazione.</p>
<pre><code>$array1 = array(4=&gt;5000,6 =&gt; 3000, 7 =&gt; 2000, 9 =&gt; 1000);
$array2 =array(0=&gt;array(...),1=&gt;array(...),2=&gt;array(...),3=&gt;array(...));

//trovo le chiavi del primo array
$keys = $keys = array_keys($array1);

//metto il pointer all'inizio dell'array
reset($keys);

//faccio un ciclo dove cancello la chiave corrente e la sostituisco in base alle chiavi del secondo array.
foreach ($array2 as $k =&gt; $v) {
   unset ($array2[$k]);

   $new_key =  current($keys);
   next($keys);
   $array2[$new_key] = $v;
}

/*
RETURN
$array2 =array(4=&gt;array(...),6=&gt;array(...),7=&gt;array(...),9=&gt;array(...));
*/
</code></pre>
<p dir="auto">Ciao a tutti !!! e buona giornata!</p>
]]></description><link>https://dev.connect.gt/post/1041114</link><guid isPermaLink="true">https://dev.connect.gt/post/1041114</guid><dc:creator><![CDATA[ceorge]]></dc:creator><pubDate>Wed, 07 Dec 2011 11:21:36 GMT</pubDate></item></channel></rss>