arrangements with the same index

0

I'm working with arrays, which has as an index the code of the person, this person example:

[PER0076] => Array
    (
        [fecha_registro] => 2018-03-27 09:52:31.642576
        [codigo_persona] => PER0076
        [cedula_ubicacion] => 0814030010000001
        [codigo_estado] => 08
        [nombre_estado] => CARABOBO
        [codigo_municipio] => 14
        [nombre_municipio] => VALENCIA
        [codigo_parroquia] => 03
        [nombre_parroquia] => URBANA MIGUEL PEÑA
        [codigo_sector] => 001
        [nombre_sector] => BRISAS DEL ARENAL
        [fecha_abordaje] => 2018-03-02
        [codigo_origen] => 1
        [origen] => Plan Vulnerabilidad
        [nombres_apellidos] => RAMON FERNANDEZ
        [cedula] => 2837999
        [fecha_nacimiento] => 1942-05-22
        [edad] => 75
        [meses] => 9
        [dias] => 8
        [genero] => 1
        [embarazo] => 2
        [cbi] => 220
        [peso] => 52.7
        [talla] => 1.62
        [descripcion_situacion] => 1
)

and this other one

[PER0076] => Array
    (
        [fecha_registro] => 2018-03-27 09:52:31.642576
        [codigo_persona] => PER0076
        [cedula_ubicacion] => 0814030010000001
        [codigo_estado] => 08
        [nombre_estado] => CARABOBO
        [codigo_municipio] => 14
        [nombre_municipio] => VALENCIA
        [codigo_parroquia] => 03
        [nombre_parroquia] => URBANA MIGUEL PEÑA
        [codigo_sector] => 001
        [nombre_sector] => BRISAS DEL ARENAL
        [fecha_abordaje] => 2018-03-02
        [codigo_origen] => 1
        [origen] => Plan Vulnerabilidad
        [nombres_apellidos] => RAMON FERNANDEZ
        [cedula] => 2837999
        [fecha_nacimiento] => 1942-05-22
        [edad] => 75
        [meses] => 9
        [dias] => 8
        [genero] => 1
        [embarazo] => 2
        [cbi] => 230
        [peso] => 58.2
        [talla] => 1.62
        [descripcion_situacion] => 1
    )

What I would like to know is how to put these two arrays into a single one where the index is the code of the person, or how you could verify if the code of the person already exists from the second only take the values from the IWC at last

    
asked by Angel Gutierrez 28.05.2018 в 17:13
source

2 answers

0

I guess you have a array of arrays therefore you can use in_array to check if there is already a arreglo within arreglo principal , how are you managing everything by indices do not Missing keys .

Example:

<?php
//Arreglo principal
$cars = array
  (
  array("Volvo",22,18),
  array("BMW",15,13),
  array("Saab",5,2),
  array("Land Rover",17,15)
  );
//Nuevo arreglo a entrar
$nuevo = array("Volvo",22,18);
//Verificas si el arreglo nuevo ya existe en el principal
if (!in_array($nuevo, $cars)) {
  //Si no existe lo agregas al arreglo
    $cars[] = $nuevo;
}
?>
    
answered by 29.05.2018 / 22:03
source
0

You can use a PHP function called array_key_exists , what it does is say: if the key exists then do not do anything to me, if not then fill me the array. Example:

//Si no existe esa llave en el array

if(!array_key_exists("PER0076",$array)){
 $array["PER0076"] = $llenarArray;
}
    
answered by 28.05.2018 в 17:36