How do I join results from different foreach in an array?

1

I'm getting movie info from a movie site using Simple Html Dom.

<?php 
include("simple_html_dom.php");

$html = file_get_html("http://arcoplex.com.br/?lang=059");

To get the titles of the movies I do:

foreach($html->find('.Cartaz .filme-single-name text') as $titulo) {
    echo $titulo . '<br>';
}

To get the src of the movie cover images I do:

foreach($html->find('.Cartaz .filme-img') as $capa) {
    echo $capa->src . '<br>';
}

To get the link from the movies I do:

foreach($html->find('.Cartaz .mais_info a') as $link) {
    echo $link->href . '<br>';
}

The result is like this:

Knowing all this, how do I merge the information of each movie into an array / json together?

Example:

{
  filmes: {
    1: {
      titulo: 'A FREIRA',
      capa: 'http://arcoiriscinemas.com.br/2014/wp-content/uploads/2018/08/mini2-1-175x285.jpg',
      link: 'http://arcoplex.com.br/filme/a-freira-2/?lang=059'
    },
    2: ...............,
    3: ...............,
    etc,
  }
}
    
asked by anonymous 24.09.2018 / 19:15

2 answers

0
<?php
    $titulo =  $html->find('.Cartaz .filme-single-name text');
    $capa =  $html->find('.Cartaz .filme-img');
    $link = $html->find('.Cartaz .mais_info a');
    $novaArray = array();
    foreach($titulo as $key => $value) {
        $novaArray[$key] = array('titulo'=>$titulo[$key],'capa'=>$capa[$key],'link'=>$link[$key]);
    }
    print_r($novaArray)

?>
    
24.09.2018 / 19:25
1

You can use array_map passing null as callback

$unido = array_map(
    null,
    $html->find('.Cartaz .filme-single-name text'),
    $html->find('.Cartaz .filme-img'),
    $html->find('.Cartaz .mais_info a')
);
    
24.09.2018 / 19:26