Tour Arrangement

0

Hello very good afternoon I would appreciate it if you can help me, I have the following arrangement:

array(3) {
  [0]=>
  array(20) {
    ["uuiddet"]=>
    string(0) ""
    ["uuid"]=>
    string(36) "63ea13a8-1c32-4456-9604-4bfa9b953100"
    ["idprod"]=>
    int(69)
    ["intcant"]=>
    int(5)
    ["dblpreciobase"]=>
    float(164.57)
    ["dbldsct1"]=>
    float(148.11)
    ["porcdsct1"]=>
    int(10)
    ["dbldsct2"]=>
    float(146.47)
    ["porcdsct2"]=>
    int(11)
    ["dbldsct3"]=>
    float(144.82)
    ["porcdsct3"]=>
    int(12)
    ["dblprecioesp"]=>
    int(0)
    ["dblpreciofin"]=>
    int(0)
    ["dblsubtotal"]=>
    float(724.1)
    ["dbligv"]=>
    float(130.34)
    ["dbltotal"]=>
    float(854.44)
    ["intestado"]=>
    int(1)
    ["vr2alerta"]=>
    string(1) "N"
    ["vr2commentalerta"]=>
    string(0) ""
    ["numcodigo"]=>
    int(123456)
  }
  [1]=>
  array(20) {
    ["uuiddet"]=>
    string(0) ""
    ["uuid"]=>
    string(36) "63ea13a8-1c32-4456-9604-4bfa9b953100"
    ["idprod"]=>
    int(70)
    ["intcant"]=>
    int(5)
    ["dblpreciobase"]=>
    float(164.57)
    ["dbldsct1"]=>
    float(148.11)
    ["porcdsct1"]=>
    int(10)
    ["dbldsct2"]=>
    float(146.47)
    ["porcdsct2"]=>
    int(11)
    ["dbldsct3"]=>
    float(144.82)
    ["porcdsct3"]=>
    int(12)
    ["dblprecioesp"]=>
    int(0)
    ["dblpreciofin"]=>
    int(0)
    ["dblsubtotal"]=>
    float(724.1)
    ["dbligv"]=>
    float(130.34)
    ["dbltotal"]=>
    float(854.44)
    ["intestado"]=>
    int(1)
    ["vr2alerta"]=>
    string(1) "N"
    ["vr2commentalerta"]=>
    string(0) ""
    ["numcodigo"]=>
    int(1285)
  }
  [2]=>
  array(20) {
    ["uuiddet"]=>
    string(0) ""
    ["uuid"]=>
    string(36) "63ea13a8-1c32-4456-9604-4bfa9b953100"
    ["idprod"]=>
    int(68)
    ["intcant"]=>
    int(5)
    ["dblpreciobase"]=>
    float(164.57)
    ["dbldsct1"]=>
    float(148.11)
    ["porcdsct1"]=>
    int(10)
    ["dbldsct2"]=>
    float(146.47)
    ["porcdsct2"]=>
    int(11)
    ["dbldsct3"]=>
    float(144.82)
    ["porcdsct3"]=>
    int(12)
    ["dblprecioesp"]=>
    int(0)
    ["dblpreciofin"]=>
    int(0)
    ["dblsubtotal"]=>
    float(724.1)
    ["dbligv"]=>
    float(130.34)
    ["dbltotal"]=>
    float(854.44)
    ["intestado"]=>
    int(1)
    ["vr2alerta"]=>
    string(1) "N"
    ["vr2commentalerta"]=>
    string(0) ""
    ["numcodigo"]=>
    int(1062)
  }
}

I would like to know how you can go

    
asked by Alexander J. Marcano 05.04.2018 в 23:43
source

1 answer

1

To traverse an associative array with PHP, you can do it with a foreach cycle, in the following way; I leave you an example

<?php
$valores = array("valor_uno" => "Alfredo", "valor_dos" => "Jorge", "valor_tres" => "Diana");

foreach($valores as $key => $value){
    echo $value.PHP_EOL;
}
//LO CUAL IMPRIMIRÁ
//Alfredo
//Jorge
//Diana

What am I placing?

  

Step inside the parentheses of the foreach the variable that stores the   array, I put an alias called $ key which in turn accesses the    $ value ; which will allow me to print as you can notice in the echo the value of each of the keys, in this case the names of   the three people

Now if you want to print both the key and the value, you can concatenate the variable $ key

$valores = array("valor_uno" => "Alfredo", "valor_dos" => "Jorge", "valor_tres" => "Diana");

foreach($valores as $key => $value){
    echo $key.' '.$value.PHP_EOL;
}
//LO CUAL IMPRIMIRÁ
//valor_uno Alfredo
//valor_dos Jorge
//valor_tres Diana

BUT I WANT TO TRAVEL A MULTIDIMENSIONAL ARRAY

  

Then you must go through it by means of 2 foreach, the first for the   main arrangement and the second for internal arrays

<?php 

$autos = array
                    (
                    array("bmw","ford","nissan"),
                    array("copet"),
                    array("Torre","Anzidi","Bleto")
                    );

 foreach($autos as $auto)
    {
    foreach($auto as $movil)
        {
        echo $movil ." ".PHP_EOL;
        }
    }
    
answered by 05.04.2018 / 23:55
source