Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.www.php > #20197

Re: aggiungere solo i nuovi elementi ad un array

From alex <1j9448a02@lnx159sneakemail.com.invalid>
Newsgroups it.comp.www.php
Subject Re: aggiungere solo i nuovi elementi ad un array
Date 2016-01-11 12:44 +0100
Organization Aioe.org NNTP Server
Message-ID <n704j1$veb$1@gioia.aioe.org> (permalink)
References <n702eb$mud$1@gioia.aioe.org>

Show all headers | View raw


Il 11/01/2016 12:07, alex ha scritto:
> /**
>   * Aggiunge al primo array, i nuovi elementi estratti dal secondo array,
>   * In altre parole, aggiunge al primo array, gli elementi contenuti nel
> secondo array,
>   * che non sono già presenti nel primo array.
>   *
>   * @param array $arr1 Il primo array.
>   * @param array $arr2 Il secondo array da cui estrarre i nuovi elementi.
>   * @return array
>   */
> function addOnlyNewElements($arr1, $arr2)
> {
>      $arr = $arr1;
>
>      /*
>       * Estrazione dei nuovi elementi dal secondo array
>       */
>      $newElements = array_diff_key($arr2, $arr1);
>
>      foreach ($newElements as $key => $value) {
>          $arr[$key] = $value;
>      }
>
>      return $arr;
> }
>
> Ma non è che esiste una funzione php nativa (già pronta) per fare quanto
> illustrato?

forse basta solo

return $arr1 + $arr2;

possibile che sia così semplice, o mi sfugge qualcosa?
o_O

Back to it.comp.www.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

aggiungere solo i nuovi elementi ad un array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2016-01-11 12:07 +0100
  Re: aggiungere solo i nuovi elementi ad un array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2016-01-11 12:44 +0100
    Re: aggiungere solo i nuovi elementi ad un array "ciccio" <21669invalid@mynewsgate.net> - 2016-01-11 15:42 +0000
      Re: aggiungere solo i nuovi elementi ad un array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2016-01-11 17:25 +0100
        Re: aggiungere solo i nuovi elementi ad un array bramante <bramante@yopmail.com> - 2016-01-11 23:39 +0100
          Re: aggiungere solo i nuovi elementi ad un array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2016-01-12 09:02 +0100
            Re: aggiungere solo i nuovi elementi ad un array Leonardo Serni <lserni@gmail.com> - 2016-01-14 14:13 +0100
              Re: aggiungere solo i nuovi elementi ad un array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2016-01-17 10:43 +0100
                Re: aggiungere solo i nuovi elementi ad un array Leonardo Serni <lserni@gmail.com> - 2016-01-17 18:38 +0100
                Re: aggiungere solo i nuovi elementi ad un array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2016-01-18 10:51 +0100

csiph-web