Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > it.comp.www.php > #19990
| From | alex <1j9448a02@lnx159sneakemail.com.invalid> |
|---|---|
| Newsgroups | it.comp.www.php |
| Subject | Re: sostituire solo gli elementi esistenti in un array |
| Date | 2015-10-10 16:15 +0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <mvb6ig$koa$1@speranza.aioe.org> (permalink) |
| References | <mvb0sp$7tg$1@speranza.aioe.org> |
Il 10/10/2015 14:38, alex ha scritto:
> $base = array("orange");
> $replacements = array(0 => "pineapple", 4 => "cherry");
>
> $basket = array_replace($base, $replacements);
> print_r($basket);
>
>
> Il problema è che viene inserito anche l'elemento 4.
> Io invece vorrei che venissero rimpiazzati solo gli elementi già
> esistenti nell'array $base (tutto il resto deve essere scartato).
>
> In pratica invece di
>
> Array (
> [0] => pineapple
> [4] => cherry
> )
>
> voglio ottenere solo
>
> Array (
> [0] => pineapple
> )
>
> Si può?
O bisogna per forza farsi una funzione a mano?
function xxx($arr1, $arr2)
{
foreach ($arr1 as $key1 => $value1) {
foreach ($arr2 as $key2 => $value2) {
if ($key1 === $key2) {
$arr1[$key1] = $arr2[$key2];
}
}
}
return $arr1;
}
Back to it.comp.www.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
sostituire solo gli elementi esistenti in un array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2015-10-10 14:38 +0200
Re: sostituire solo gli elementi esistenti in un array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2015-10-10 16:15 +0200
Re: sostituire solo gli elementi esistenti in un array fmigliori <fmigliori@gmail.com> - 2015-10-10 23:56 -0700
Re: sostituire solo gli elementi esistenti in un array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2015-10-11 11:13 +0200
Re: sostituire solo gli elementi esistenti in un array fmigliori <fmigliori@gmail.com> - 2015-10-11 03:37 -0700
Re: sostituire solo gli elementi esistenti in un array Leonardo Serni <lserni@gmail.com> - 2015-10-11 13:26 +0200
Re: sostituire solo gli elementi esistenti in un array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2015-10-12 20:27 +0200
Re: sostituire solo gli elementi esistenti in un array Leonardo Serni <lserni@gmail.com> - 2015-10-11 13:19 +0200
Re: sostituire solo gli elementi esistenti in un array Leonardo Serni <lserni@gmail.com> - 2015-10-11 13:23 +0200
Re: sostituire solo gli elementi esistenti in un array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2015-10-12 20:36 +0200
csiph-web