Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Mobile (3)
- Auburn (2)
- Array
- (
- [0] => Array
- (
- [0] => Array
- (
- [city] => Mobile
- [numLocations] => 3
- )
- [1] => Array
- (
- [city] => Auburn
- [numLocations] => 2
- )
- )
- )
- while($row = mysqli_fetch_assoc($result)){
- $state = $row['state'];
- $stateAbv = $row['stateAbv'];
- $city = $row['city'];
- $numSLocations = $values['cnt'];
- if (!isset($rows[$row['state']])){
- $rows[$row['state']] = array();
- }
- $rows[$row['state']][] = ['city' => $city, 'numLocations' => $numStores];
- }
- foreach($rows as $state => $cities){
- echo array_column($cities, 'numLocations'));
- }
- while($row = mysqli_fetch_assoc($result)){
- if (!isset($rows[$row['state']])) $rows[$row['state']] = 0; //initialize with 0
- $rows[$row['state']] += $row['cnt']; //increment the num Stores
- }
- ['Mobile' => 3, 'Auburn' => 2]
- $numSLocations = $values['cnt'];
- foreach($rows as $state => $num){
- echo "$state ($num)nn";
- }
- Mobile (3)
- Auburn (2)
- print_r(array_column($array[0], 'numLocations', 'city'));
- foreach($rows as $state => $cities){
- echo array_column($cities, 'numLocations')); //returns an array
- }
- [0 => 3,1 => 2]
- array_column($array[0], 'numLocations')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement