Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1838040
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:25:45+00:00 2026-05-17T06:25:45+00:00

Say i am having set of rows in a table and each row is

  • 0

Say i am having set of rows in a table and each row is having a column called city with some values assigned to it
iam iterating through the result set and i need to assign the list of city values of each row in to an array only unique

     foreach($res as $row){
       $cities =array();
       $cities[] = $row['city'];
       //when i say 
       var_dump($cities);
       //Iam not able to get array .how do i do that 
       $maincities = array('A','B',C)
     }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:25:45+00:00Added an answer on May 17, 2026 at 6:25 am

    You’re resetting $cities to a new array for each row you loop through. Better would be:

    $cities = array();
    foreach ($res as $row)
    {
        if ( ! in_array($row['city'], $cities)) {
            $cities[] = $row['city'];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am having some arguments say (String a, Treeset b, Set c) and I try
I have this strange scenario. I have a table having multiple rows (each generated
I have a table with timestamped rows: say, some feed with authors: CREATE TEMPORARY
I am having a table named tblA.I am having the following set of values.
I having two arrays say, $array1 = array(code => E0089, desc => some description);
I´m having some trouble retrieving a collection of strings in a projection: say that
Say, you have table T(C1, C2, C3) and there is a set of valid
I have a column called CODE in a MySQL table which can be NULL.
I am having a large data set (number based data, for example, 200,000 rows
I am having a set of text fields where i am doing validation Say

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.