How to go through this array

1

I have this array, in this way let's say putting the offset which is the 0 .

Manually works what I want is that you return all the values of that array without me putting the offset

$data_array[$section_key][$section_data_key][$block_key]['content_block_images'] = brc_make_link_relative_if_local(wp_get_attachment_url( $data_array[$section_key][$section_data_key][$block_key]['content_block_images']['0']['image'] ) );
    
asked by Santiago D'Antuoni 23.11.2016 в 18:52
source

2 answers

4
  // Función recursiva que recorre un array tantos elementos y dimensiones contenga
function recorrer_array_recursivo($array)
{
  foreach($array as $value)
  {
    // Si es un array, invoco de nuevo la función
    if(is_array($value))
    {
      recorrer_array_recursivo($value);
    }else{

    // Si no, imprimo el valor. Aquí puedes almacenar la info en vez de imprimir. 
      echo $value;
    }
  }
}

For tests:

$a = array( array( array( array(1)), 2, 3 ), array( 4, 5, 6), 7, 8);


recorrer_array_recursivo($a);

Execute this function with your array and comment. Greetings.

    
answered by 23.11.2016 в 19:03
1

I'm not sure I understand what you need, but suppose that:

  

What you want, is to set is in the position $data_array[$section_key][$section_data_key][$block_key]['content_block_images'] , all the links to the images within.

Then you could do this:

    // Hacemos uso de asignación por referencia
    $images = &$data_array[$section_key][$section_data_key][$block_key]['content_block_images'];
    $links = '';

    // Recorremos el arreglo de imagenes
    foreach($images as $info) {
      // Obtenemos los links
      $links .= brc_make_link_relative_if_local(wp_get_attachment_url( $info['image']));
    }
    // Sobre escribimos el valor
    $images = $links;

What are references doing?

    
answered by 23.11.2016 в 19:46