#19617 [Fbk->NoF]: Array_multisort don't work on GLOBAL array

From: Date: Tue, 15 Oct 2002 00:37:40 +0000
Subject: #19617 [Fbk->NoF]: Array_multisort don't work on GLOBAL array
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-22443@lists.php.net to get a copy of this message
ID: 19617 Updated by: sniper@php.net Reported By: jpapin@free.fr -Status: Feedback +Status: No Feedback Bug Type: Arrays related Operating System: Unix PHP Version: 4.2.0 New Comment: No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Open". Thank you. Previous Comments: ------------------------------------------------------------------------ [2002-09-26 11:14:55] sniper@php.net Works fine here with latest CVS head. Please, try PHP 4.2.3. (4.2.0 is really too old..) ------------------------------------------------------------------------ [2002-09-26 11:11:59] jpapin@free.fr Sorry, try this with and without "global $row;" <? function t() { global $row; $row = array(array("1","Php"),array(2,"I"),array(3,"Love")); foreach ( $row as $value ) { $sortarray[] = $value[1]; } array_multisort($sortarray,$row); print_r($row); echo "<br>"; print_r($sortarray); } t(); ?> ------------------------------------------------------------------------ [2002-09-26 10:42:59] sniper@php.net Please provide a short (!) complete and self-containing example script. You should also try with the 4.2.3 release. ------------------------------------------------------------------------ [2002-09-26 10:13:43] jpapin@free.fr Using array_multisort in a function don't work if the array is "global" (you can paste the following code) : <HTML> <HEAD> <TITLE></TITLE> </HEAD> <body> <? function t() { global $row; $file = fopen("file.txt","r") or die; while (!feof($file)) { $row[] = fgetcsv($file,80,";"); } /* $row[] like this Array ( [0] => Array ( [0] => 406 [1] => xxxxxxxxxxxxxxxxxxxx [2] => 5,72 ) [1] => Array ( [0] => 001 [1] => zzzzzzzzzzzzzzzzzzzzz [2] => 5,77 ) [2] => Array ( [0] => 402 [1] => aaaaaaaaaaaaaaaaaaaaa [2] => 13,71 ) [3] => Array ( [0] => 009 [1] => fffffffffffffffffffff [2] => 7,61 ) ) I want to sort it on aaa.../fff.../xxx.../zzz... */ fclose($file); foreach ( $row as $value ) { $sortarray[] = $value[1]; } /* $sortarray like this Array ( [0] => xxxxxxxxxxxxxxxxxxxx [1] => zzzzzzzzzzzzzzzzzzzz [2] => aaaaaaaaaaaaaaaaaaaa [3] => ffffffffffffffffffff ) */ // I try to use array_multisort($row,$sortarray); too array_multisort($sortarray,$row); print_r($row); // no change for $row[], until i remove global for $row; echo "<br>"; print_r($sortarray); /* $sortarray[], now like this Array ( [0] => aaaaaaaaaaaaaaaaaaaa [1] => ffffffffffffffffffff [2] => xxxxxxxxxxxxxxxxxxxx [3] => zzzzzzzzzzzzzzzzzzzz ) or no change if set to global too. */ } t(); ?> </body> </HTML> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=19617&edit=1

« previous php.bugs (#22443) next »