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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:44:38+00:00 2026-06-04T00:44:38+00:00

My data 1 : aaa 2 : bbb 2 : ccc 3 : ddd

  • 0

My data

1 : "aaa"
2 : "bbb"
2 : "ccc"
3 : "ddd"
4 : "eee"
4 : "fff"
4 : "ggg"

How could I keep these value in PHP array ?
Are there any for-loop implementation example ?

[edited]
How to make this array from my data via for-loop php ?

$array = array(
   1 => array("aaa"), 
   2 => array("bbb", "ccc"), 
   3 => array("ddd"),
   4 => array("eee", "fff", "ggg")
);

[edited#2]
My real code:

$list = "SELECT.....";    
$root = retrieve($list);
// $root is a array of the data from PostgreSQL;
foreach($root as $i => $v){
    if(cond) {
        $q = "SELECT ...(use variables from $root)";
        $a = retrieve($q);  
        for($a as $j => $w) {
            echo $index." ".$v["aid"]." ".$w['new_geom']."<br />";
        }
        //what this line printed, i simplified to the sample data above
        $index++;           
    }   
} 

[edited#3]
this is what it print

...
23 33 "aaa"
24 34 "bbb" 
25 34 "ccc" 
26 35 "ddd" 
...
  • 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-04T00:44:40+00:00Added an answer on June 4, 2026 at 12:44 am

    I’m guessing this is what you want. I’m also guessing that $v['aid'] contains the index of the new array you want and that $w['new_geom'] contains the values, e.g.: aaa, bbb etc

    $list = "SELECT.....";    
    $root = retrieve($list);
    
    $theNewArray = array();
    foreach($root as $i => $v){
        if(cond) {
            $q = "SELECT ...(use variables from $root)";
            $a = retrieve($q);  
            for($a as $j => $w) {
                if (!array_key_exists($v["aid"], $theNewArray)) {
                    $theNewArray[$v["aid"]] =  array();
                }
    
                $theNewArray[$v["aid"]][] = $w['new_geom'];
    
                echo $index." ".$v["aid"]." ".$w['new_geom']."<br />";
            }
            //what this line printed, i simplified to the sample data above
            $index++;           
        }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Excel Sheet data Eno EName Pincode 1 aaa 123456 2 bbb 123423 3 ccc
I would like make: aaa | bbb | ccc | ddd etc 1 |
class a(object): data={'a':'aaa','b':'bbb','c':'ccc'} def pop(self, key, *args): return self.data.pop(key, *args)#what is this mean. b=a()
I have a file called one_to_many.txt. In the file is the data: a,aaa b,bbb
I'm stuck to getting data from this xml: <?xml version=1.0 encoding=UTF-8?> <document> <AAA>Header</AAA> <BBB>
id | name 1 | aaa 2 | bbb 3 | ccc 4 |
[ { id: 123, name: aaa }, { id: 567, name: bbb }, {
I have a PHP array that I'd like to duplicate but only copy elements
I want a SQL query to display the following data ID Name 1 AAA
Let's say I have data as below: aaa m7 aaa m9 aaa m7 aaa

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.