Browse an array where the index is a Date

Asked

Viewed 67 times

2

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

Just a detail, the dates are dynamic at each consultation.

The Array arrives that 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
        )

)
  • foreach ($array as $data => $valor) { ... }?

  • @Andersoncarloswoss Dates are dynamic

  • But it makes no difference.

  • @Andersoncarloswoss and how I catch [Conteudoid]?

2 answers

2

You can use the 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";
   }

Upshot:

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

Documentation - Foreach

2

Riding 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 content you need, so just do as the example above to access the value $value['content'];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.