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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:17:10+00:00 2026-06-01T06:17:10+00:00

I have an array with this structure: array(4) { [0]=> array(x) { [0]=> string(x)London

  • 0

I have an array with this structure:

array(4) { 
     [0]=> array(x) { 
        [0]=> string(x)"London" 
        [1]=> string(xx) "John"}
     [1]=> array(x) { 
        [0]=> string(x)"London" 
        [1]=> string(xx) "Charles"}
     [2]=> array(x) { 
        [0]=> string(x)"Paris" 
        [1]=> string(xx) "Alan"}
     [3]=> array(x) { 
        [0]=> string(x)"Paris" 
        [1]=> string(x) "Wayne"} 
    }

How can I display the array data in this order:

London

John | Charles

Paris

Alan | Wayne

This can be done with an unique multidimensional array? or should i have another array to select distinct cities?

I am talking about something like a loop with:

foreach ($cities as $city) {
    echo '<div class="city">'.$city.'</div>';
        for() {
            echo '<div class="persons">'.$persons.'</div>';
        }
}

thanks

  • 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-01T06:17:12+00:00Added an answer on June 1, 2026 at 6:17 am

    Group your cities in a new array, then spit it out

    $newCities = array();
    
    foreach ($cities as $city) {
        $newCities[$city[0]][] = $city[1];
    }
    
    foreach($newCities as $city => $persons) {
       echo '<div class="city">' . $city . '</div>';
    
       // use join to glue the pieces together
       echo '<div class="persons">' . join(' | ', $persons) . '</div>';
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of structure like this: Structure Planner Dim Type As String
I have this string : 0=&task=rose&duration=1.25&user=15&1=&task=daisy&duration=0.75&user=25&2=&task=orchid&duration=1.15&user=7 I want this array structure : array( array(
I have an array structure that looks like this: Array ( [0] => Array
Lets say I have an array with a structure like this: $arr= Array( array(
I have two arrays the first one has this structure Parameter Keys array array
Let's say I have an array like this: $array = array (this,is,me,and,I,am,an,array,hello,beautiful,world); How can
I have an array of structures: Public Structure emp Public empName As String Public
I have an array which have this structure: $queues[n] Array ( [id] => integer
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]

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.