Sort Array of a file_get_html

2

I have this strange case, I hope you help me. I am trying to sort the result of an array Extracted with DOM but it does not work for me

Code:

include('../simple_html_dom.php');

$html = file_get_html('http://Google.com/');

$links = array();

$orden= array_splice($links, 0,0,54) // utilizo esta función para ordenar los arrays y mostrar los últimos 

foreach($html->find('a') as $a) {
 $orden[] = $a->href;
}
print_r($orden);

RESUTADO

  

Array ([0] = >

     

1- link 1 2- link 2 3 - link 3 ............. (Show as 50   elements and I want to limit it to 5 for example)

     

1- link 1 2- link 2 3 - link 3 4- link 4 5- link 5

In summary array_splice promises to do that but it does not work, what am I doing wrong?

    
asked by Bryan B Weiss 31.01.2016 в 14:31
source

1 answer

3

According to what I read here array_splice does not serve to sort a array .

array array_splice ( array &$input , 
                     int $offset [, int $length = 0 [, mixed $replacement = array() ]] )

What it does is starting from a $offset to a $length eliminates those indexes and replaces them by what is contained in $replacement . The reference says that if $replacement is not a array , it will be converted to one.

In your case you pass flames to array_splice($links,0,0,54) this causes no change in array $links since $length is 0 .

Maybe you're using the wrong function.

Here you have some help links:

answered by 02.02.2016 / 13:41
source