Search the Community
Showing results for tags 'sort array'.
-
I'm having an issue sorting an array. I'm getting an error of "Warning: ksort() expects parameter 1 to be array, null given in" The print_r output of the array is Array ( [0] => Array ( [text] => 96.1 km [value] => 96113 ) [1] => Array ( [text] => 52.1 km [value] => 52096 ) [2] => Array ( [text] => 102 km [value] => 102064 ) [3] => Array ( [text] => 30.0 km [value] => 29992 ) [4] => Array ( [text] => 43.9 km [value] => 43864 ) [5] => Array ( [text] => 57.4 km [value] => 57408 ) [6] => Array ( [text] => 82.2 km [value] => 82154 ) [7] => Array ( [text] => 73.6 km [value] => 73620 ) [8] => Array ( [text] => 118 km [value] => 118016 ) [9] => Array ( [text] => 137 km [value] => 136921 ) [10] => Array ( [text] => 61.6 km [value] => 61574 ) [11] => Array ( [text] => 74.2 km [value] => 74193 ) [12] => Array ( [text] => 226 km [value] => 226166 ) [13] => Array ( [text] => 140 km [value] => 140145 ) [14] => Array ( [text] => 126 km [value] => 126140 ) [15] => Array ( [text] => 45.5 km [value] => 45520 ) [16] => Array ( [text] => 211 km [value] => 211070 ) [17] => Array ( [text] => 54.1 km [value] => 54145 ) [18] => Array ( [text] => 187 km [value] => 186855 ) [19] => Array ( [text] => 271 km [value] => 271334 ) [20] => Array ( [text] => 219 km [value] => 218848 ) [21] => Array ( [text] => 67.0 km [value] => 67016 ) [22] => Array ( [text] => 13.6 km [value] => 13591 ) [23] => Array ( [text] => 153 km [value] => 153396 ) [24] => Array ( [text] => 11.5 km [value] => 11492 ) ). All I want to do is be able to sort the array by the lowest number in either text or value and display that single number. <?php include 'config/db_functions.php'; //run the query $loop = mysql_query("SELECT * FROM NEW_Venues WHERE game_nights = '5' AND status = '1'") or die (mysql_error()); while ($row = mysql_fetch_array($loop)) { $postcode2 = $row['zip']; $venue = $row['venue']; $postcode1=('33071');; $url = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=$postcode2&destinations=$postcode1&mode=driving&language=en-EN&sensor=false"; $data = @file_get_contents($url); $result = json_decode($data, true); ksort($items); foreach($result['rows'] as $distance) {; echo '' . $venue . ' - ' . $distance['elements'][0]['distance']['text'] . ' <br>'; $items[] = $distance['elements'][0]['distance']; $items1[] = $distance['elements'][0]['distance']; $itemsname[] = $venue; } } ksort($items1); foreach ($items1 as $key => $val) { echo "$key = $val <br>"; } print_r(array_values($items)); ?>
- 16 replies
-
- php
- sort array
-
(and 1 more)
Tagged with: