Go through an array where the index is a Date

2

How do I go through an Array where the index is a date that varies with each query in the database.

Just one detail, the dates are dynamic with each query.

Array arrives this way:

Array
(
    [2018-04-07] => Array
        (
            [ConteudoId] => 28498
        )

    [2018-04-08] => Array
        (
            [ConteudoId] => 28498
        )

    [2018-05-05] => Array
        (
            [ConteudoId] => 28762
        )

    [2018-05-06] => Array
        (
            [ConteudoId] => 28762
        )

    [2018-06-16] => Array
        (
            [ConteudoId] => 28765
        )

    [2018-06-17] => Array
        (
            [ConteudoId] => 28765
        )

    [2018-07-06] => Array
        (
            [ConteudoId] => 28764
        )

    [2018-07-07] => Array
        (
            [ConteudoId] => 28764
        )

)
    
asked by anonymous 29.03.2018 / 19:23

2 answers

2

You can use foreach

Example:

 $array = array("2018-04-07" => array("conteudoid" => "a"),  
              "2018-04-08" => array("conteudoid" => "b"),
              "2018-04-09" => array("conteudoid" => "c"));

   foreach( $array as $key => $value ){
     echo "$key => $value[conteudoid] \n";
   }

Result:

2018-04-07 => a 
2018-04-08 => b 
2018-04-09 => c 

Documentation - Foreach

    
29.03.2018 / 19:27
2

Traversing with a foreach

Ex:

foreach ($arrayBanco as $chave => $valor) {
    echo $valor['conteudoID'];
}

Note that in your code each position of the main array returns another array, which is where you find the contentID you need, so just do as above example to access $ value ['contentID'];

    
29.03.2018 / 22:17