fork download
  1. <?php
  2.  
  3. function cmpSites($a, $b)
  4. {
  5. return strcmp($a["sites"], $b["sites"]);
  6. }
  7.  
  8. function cmpIPs($a, $b)
  9. {
  10. return strcmp($a["IPs"], $b["IPs"]);
  11. }
  12.  
  13. $lista_estacoes = array( "google", "facebook", "twitter", "stackoverflow" );
  14. $lista_enderecos = array ( "200.281.4.213", "189.12.4.61", "201.218.1.20", "187.29.103.44");
  15.  
  16. usort($lista_estacoes, "cmpSites");
  17. usort($lista_enderecos, "cmpIps");
  18.  
  19. $data = array( 'sites' => $lista_estacoes, 'IPs' => $lista_enderecos);
  20.  
  21. var_dump($data);
Success #stdin #stdout #stderr 0.02s 24448KB
stdin
Standard input is empty
stdout
array(2) {
  ["sites"]=>
  array(4) {
    [0]=>
    string(8) "facebook"
    [1]=>
    string(6) "google"
    [2]=>
    string(13) "stackoverflow"
    [3]=>
    string(7) "twitter"
  }
  ["IPs"]=>
  array(4) {
    [0]=>
    string(13) "187.29.103.44"
    [1]=>
    string(11) "189.12.4.61"
    [2]=>
    string(13) "200.281.4.213"
    [3]=>
    string(12) "201.218.1.20"
  }
}
stderr
PHP Warning:  Illegal string offset 'sites' in /home/lh42mH/prog.php on line 5
PHP Warning:  Illegal string offset 'sites' in /home/lh42mH/prog.php on line 5
PHP Warning:  Illegal string offset 'sites' in /home/lh42mH/prog.php on line 5
PHP Warning:  Illegal string offset 'sites' in /home/lh42mH/prog.php on line 5
PHP Warning:  Illegal string offset 'sites' in /home/lh42mH/prog.php on line 5
PHP Warning:  Illegal string offset 'sites' in /home/lh42mH/prog.php on line 5
PHP Warning:  Illegal string offset 'sites' in /home/lh42mH/prog.php on line 5
PHP Warning:  Illegal string offset 'sites' in /home/lh42mH/prog.php on line 5
PHP Warning:  Illegal string offset 'sites' in /home/lh42mH/prog.php on line 5
PHP Warning:  Illegal string offset 'sites' in /home/lh42mH/prog.php on line 5
PHP Warning:  Illegal string offset 'sites' in /home/lh42mH/prog.php on line 5
PHP Warning:  Illegal string offset 'sites' in /home/lh42mH/prog.php on line 5
PHP Warning:  Illegal string offset 'sites' in /home/lh42mH/prog.php on line 5
PHP Warning:  Illegal string offset 'sites' in /home/lh42mH/prog.php on line 5
PHP Warning:  Illegal string offset 'IPs' in /home/lh42mH/prog.php on line 10
PHP Warning:  Illegal string offset 'IPs' in /home/lh42mH/prog.php on line 10
PHP Warning:  Illegal string offset 'IPs' in /home/lh42mH/prog.php on line 10
PHP Warning:  Illegal string offset 'IPs' in /home/lh42mH/prog.php on line 10
PHP Warning:  Illegal string offset 'IPs' in /home/lh42mH/prog.php on line 10
PHP Warning:  Illegal string offset 'IPs' in /home/lh42mH/prog.php on line 10
PHP Warning:  Illegal string offset 'IPs' in /home/lh42mH/prog.php on line 10
PHP Warning:  Illegal string offset 'IPs' in /home/lh42mH/prog.php on line 10