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 7764833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:01:03+00:00 2026-06-01T15:01:03+00:00

I have a PDO Query that returns what appears to be an array $pds.

  • 0

I have a PDO Query that returns what appears to be an array $pds. I can loop through this array as follows:

foreach ($pds as $row) {

 }

I need to loop through the same array a second time but when I do this there doesn’t appear to be any data in the array. Also I’ve tried to copy the array as follows:

 $pds2 = $pds;

Is there a trick I’m missing to use this array twice?

thx

Code:

        // Remove Duplicate Locations where words are in a different order
        $cityArray = $pds;

        foreach ($cityArray as $data) {
            $words = explode(' ', $data['city'] . ' ' . $data['region1'] . ' ' . $data['region2'] . ' ' . $data['region3']);
            sort($words);
            $cityWordsArray[$data['id']] = implode(' ', $words);
        }
        $cityWordsArray = array_unique($cityWordsArray);

        foreach ($pds as $row) {
            echo 'hi';
            foreach($cityWordsArray as $key=>$value) {
                if($row['id'] == $key) {
  • 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-06-01T15:01:05+00:00Added an answer on June 1, 2026 at 3:01 pm

    I’m afraid that $pds is not an array, but a PDOStatement.

    If you want to get as an array, you should use fetchAll to get the result as an array.

    Try $pds = $pds->fetchAll(); before the loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have something like this: $db=new PDO($dsn); $statement=$db->query('Select * from foo'); while
I am going through this tutorial about PDO and have come to the point
If I use PDO and use FETCH_INTO like ... $query->setFetchMode(PDO::FETCH_INTO, $this); $query->execute(); I have
I have a simple recursive array function that looks like this: function recursive_array($results) {
I'm a newcomer to PDO and have to say that I like it so
I have an issue with PDO that I'd really like to get an answer
I am developing an ORM based on PDO, for tables that don't have unique
I have this query: public function checkUser($phone) { $sql = SELECT name FROM users
I'm using PDO inside a database abstraction library function query that I've made. I'm
Different databases have slight variations in their implementations of SQL. Does PDO handle this?

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.