Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Array: changing values
    primarykey
    data
    text
    <p>I have this array:</p> <pre><code> Array ( [0] =&gt; Array ( [menu_id] =&gt; 8 [menu_children] =&gt; 0 [menu_voce] =&gt; Eventi [menu_alias] =&gt; eventi [menu_pubblicato] =&gt; 1 [pagine_id] =&gt; 6 [pagine_titolo] =&gt; Pagina degli eventi [pagine_descrizione] =&gt; pagina eventi [pagine_testo] =&gt; &lt;p&gt;eventi&lt;/p&gt; [pagine_creato] =&gt; 2013-12-04 18:49:49 [pagine_template] =&gt; base.html [pagine_aggiornato] =&gt; [pagine_timezone] =&gt; Europe/Rome [childs] =&gt; Array ( [0] =&gt; Array ( [menu_id] =&gt; 9 [menu_children] =&gt; 8 [menu_voce] =&gt; Natale [menu_alias] =&gt; natale [menu_pubblicato] =&gt; 1 [pagine_id] =&gt; 7 [pagine_titolo] =&gt; natale 2013 [pagine_descrizione] =&gt; natale 2013 [pagine_testo] =&gt; &lt;p&gt;natale 2013!&lt;/p&gt; [pagine_creato] =&gt; 2013-12-04 19:09:57 [pagine_template] =&gt; base.html [pagine_aggiornato] =&gt; [pagine_timezone] =&gt; Europe/Rome ) ) ) [1] =&gt; Array ( [menu_id] =&gt; 10 [menu_children] =&gt; 0 [menu_voce] =&gt; Promozioni [menu_alias] =&gt; promozioni [menu_pubblicato] =&gt; 1 [pagine_id] =&gt; 8 [pagine_titolo] =&gt; promozioni [pagine_descrizione] =&gt; promozioni [pagine_testo] =&gt; &lt;p&gt;promozioni&lt;/p&gt; [pagine_creato] =&gt; 2013-12-04 19:17:37 [pagine_template] =&gt; base.html [pagine_aggiornato] =&gt; [pagine_timezone] =&gt; Europe/Rome ) ) </code></pre> <p>I need to change the values in "pagine_aggiornato" == "pagine_creato" if "pagine_aggiornato" is empty, and after this i need to call a no-standard function.</p> <p>In pseudo code:</p> <pre><code> if $pageTree['pagine_aggiornato'] == '' { $pageTree['pagine_aggiornato']=localizzaData($pageTree['pagine_creato'],UTF); } else { $pageTree['pagine_aggiornato'] = localizzaData($pageTree['pagine_aggiornato'],UTF); } </code></pre> <p>The problem is that is it possible that exists a "Childs" subarray, depending if there is a submenu or not.</p> <p>Could you please help me to write the smart and fast code to edit this array? Thank you</p> <p>EDIT:</p> <p>With the hint of umulder I'm using the array_walk_recursive, but I have every time the "pagine_aggiornato" value null.</p> <p>This is code:</p> <pre><code>function _update_key_array(&amp;$item,$key) { if ($key=='pagine_creato') { $creazione = $item; if($key=='pagine_aggiornato') { if ($item=='') { $item = $creazione; } } } } array_walk_recursive($pageTree,'_update_key_array'); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload