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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:31:04+00:00 2026-05-26T08:31:04+00:00

I have something similar to the following structure: Array ( [wp_postmeta] => Array (

  • 0

I have something similar to the following structure:

Array
(
    [wp_postmeta] => Array
    (
        [0] => stdClass Object
            (
                [meta_id] => 1
                [post_id] => 2
                [meta_key] => _wp_page_template
                [meta_value] => default
            )

    )

    [wp_comments] => Array
    (
        [0] => stdClass Object
            (
                [comment_ID] => 1
                [comment_post_ID] => 1
                [comment_author] => Mr WordPress
                [comment_author_email] => 
                [comment_author_url] => http://wordpress.org/
                [comment_author_IP] => 
                [comment_date] => 2011-10-20 03:06:23
                [comment_date_gmt] => 2011-10-20 03:06:23
                [comment_content] => Hi, this is a comment.
                [comment_karma] => 0
                [comment_approved] => 1
                [comment_agent] => 
                [comment_type] => 
                [comment_parent] => 0
                [user_id] => 0
            )

    )
)

What I’m trying to do here is iterate over these results so I can use them to form a query.

Assume all the data within the wp_postmeta table is deleted from the database and this array contains the data of that table before it was deleted. I want to take this saved data in the array and reset the table with these old values.

I.e Looping through the array and inserting this as sql: INSERT INTO wp_postmeta (meta_id, post_id, meta_key, meta_value) VALUES (1, 2, ‘_wp_page_template’, ‘default’)

  • 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-26T08:31:05+00:00Added an answer on May 26, 2026 at 8:31 am
    foreach ($outerArray as $tableName => $tableData) { // Loop outer array
      foreach ($tableData as $row) { // Loop table rows
        $cols = $vals = array();
        foreach ($row as $col => $val) { // Loop this row
          $cols[] = $col;
          $vals[] = $val; // You may need to escape this before using it in a query...
        }
        // Build the query
        $query = "INSERT INTO $tableName (".implode(', ',$cols).") VALUES ('".implode("', '",$vals)."')";
        // Do the query here
      }
    }
    

    You can iterate over object properties just like you can with an array, and in a stdClass everything is public, so the above should work no problem.

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

Sidebar

Related Questions

I have something similar to the following method: public ActionResult Details(int id) { var
i have something similar to the following... used a python script to JSON to
We currently have an ant task that contains something similar to the following: <filelist
I have an object with event handlers and I want to make something similar
I have something similar to the following table: ================================================ | Id | UserId |
I have a table structure similar to the following example: DateTime V1 V2 V3
I have something similar to the following selector: $('div, span', $('.test')).selector I expect the
I have something similar to the following WHERE clause in my SQL statement: AND
I have two hashes which have a structure something similar to this: hash_a =
I have something that looks like the following document structure: public class Document {

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.