Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. Mobile (3)
  2. Auburn (2)
  3.  
  4. Array
  5. (
  6. [0] => Array
  7. (
  8. [0] => Array
  9. (
  10. [city] => Mobile
  11. [numLocations] => 3
  12. )
  13.  
  14. [1] => Array
  15. (
  16. [city] => Auburn
  17. [numLocations] => 2
  18. )
  19.  
  20. )
  21.  
  22. )
  23.  
  24. while($row = mysqli_fetch_assoc($result)){
  25. $state = $row['state'];
  26. $stateAbv = $row['stateAbv'];
  27. $city = $row['city'];
  28. $numSLocations = $values['cnt'];
  29.  
  30. if (!isset($rows[$row['state']])){
  31. $rows[$row['state']] = array();
  32. }
  33.  
  34. $rows[$row['state']][] = ['city' => $city, 'numLocations' => $numStores];
  35. }
  36.  
  37. foreach($rows as $state => $cities){
  38. echo array_column($cities, 'numLocations'));
  39. }
  40.  
  41. while($row = mysqli_fetch_assoc($result)){
  42. if (!isset($rows[$row['state']])) $rows[$row['state']] = 0; //initialize with 0
  43.  
  44. $rows[$row['state']] += $row['cnt']; //increment the num Stores
  45. }
  46.  
  47. ['Mobile' => 3, 'Auburn' => 2]
  48.  
  49. $numSLocations = $values['cnt'];
  50.  
  51. foreach($rows as $state => $num){
  52. echo "$state ($num)nn";
  53. }
  54.  
  55. Mobile (3)
  56.  
  57. Auburn (2)
  58.  
  59. print_r(array_column($array[0], 'numLocations', 'city'));
  60.  
  61. foreach($rows as $state => $cities){
  62. echo array_column($cities, 'numLocations')); //returns an array
  63. }
  64.  
  65. [0 => 3,1 => 2]
  66.  
  67. array_column($array[0], 'numLocations')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement