[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-general-es
Subject:    Re: [PHP-ES] Combinando arrays.
From:       Mariano Guezuraga <alfatester () gmail ! com>
Date:       2009-03-27 15:17:39
Message-ID: ae7f2e160903270817q7651740dh6d3b148b0f64c7ef () mail ! gmail ! com
[Download RAW message or body]

2009/3/27 Pablo Braulio <brulics@gmail.com>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hola de nuevo.
>
> Sigo pegandome con mi array, pero ahora trato de combinar dos arrays.
>
> Tengo los siguientes arrays.
>
> array(
> [0] => array("host" => "NOMBRE1"),
> [1] => array("host" => "NOMBRE2"),
> [2] => array("host" => "NOMBRE3"))
>
> array(
> [0] => array("so" => "VALOR1"),
> [1] => array("so" => "VALOR2"),
> [2] => array("so" => "VALOR3"))
>
> Quiero construir un arrar de este tipo:
>
> array(
> [0] => array("host" => "NOMBRE1", "so" => "VALOR1"),
> [1] => array("host" => "NOMBRE2", "so" => "VALOR2"),
> [2] => array("host" => "NOMBRE3", "so" => "VALOR3"))
>
> He probado con varias funciones de arrays (array_combine,
> array_intersect, etc), sin exito.
>
> żAlguna idea?.
> - --
> Saludos cordiales.
> Pablo.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAknM7KIACgkQK7lGsMchFsw5hQCeJf1NlkrlrsPoRMWerRkeao2F
> 9KYAnjflScg/+Zs1oLByKMGJTC7gnsnY
> =bgx2
> -----END PGP SIGNATURE-----
>
> --
> PHP Spanish Localization Talk Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Recorrer uno de los 2 y usar esa clave para acceder al elemento del otro array.

digamos que este es un array $hosts
 array(
 [0] => array("host" => "NOMBRE1"),
 [1] => array("host" => "NOMBRE2"),
 [2] => array("host" => "NOMBRE3"))

y este, otro $so
> array(
> [0] => array("so" => "VALOR1"),
> [1] => array("so" => "VALOR2"),
> [2] => array("so" => "VALOR3"))
>

$resultado = array();
for ($i = 0; $i < count($hosts); $i++) {
   $resultado[] = array($hosts[$i]['host'] => $so[$i]['so');
}

-- 
PHP Spanish Localization Talk Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic