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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:25:15+00:00 2026-06-13T02:25:15+00:00

I have the following code which grabs two separate arrays, flips the surname and

  • 0

I have the following code which grabs two separate arrays, flips the surname and firstname (also removes the comma) and outputs this:

Director: Bert & Bertie

Writer: Bert & Bertie

Producer: Louise Knight

Producer: Miles Wilkes

Producer: Andy Welch

Actor: Craig Parkinson

Actor: Camilla Rutherford

Actor: Paul Bhattarcharjee

Actor: Ford Kieman

Actor: Maurren the Pug

Actor: Hannah Walters

DP: Lynda Hall

Cut: Matt Chodan

What I need to do is to group similar groups to output something like this:

Director: Bert & Bertie

Writer: Bert & Bertie

Producer: Louise Knight, Miles Wilkes, Andy Welch

Actors: Craig Parkinson, Camilla Rutherford, Paul Bhattarcharjee, Ford Kieman, Maurren the Pug, Hannah Walters

DP: Lynda Hall

Cut: Matt Chodan

Current PHP Code:

<?php 
$arrayname=explode(":::",$dwzXmlRec_1->GetFieldValue("PERSON_NAME"));
$arraynamel=count($arrayname);
$arrayrole=explode(":::",$dwzXmlRec_1->GetFieldValue("PERSON_FUNCTION"));   
$arrayrolel=count($arrayrole);

$name = "Lastname, Firstname"; 
$names = explode(", ", $name); 
$name = $names[1] . " " . $names[0]; 

for($i=0;$i<$arrayrolel;$i++) 
    { 
        $names = explode(", ", $arrayname[$i]); 
        $name = $names[1] . " " . $names[0];
        echo $arrayrole[$i].': '.$name.'<br />';
    } 
?>

UPDATE: Just one question, the data is set from an xml node, and since it’s in array "as" is One role comes before another. For Example, ‘Actor’ comes first, then ‘Director’. Is there any easy method to reverse it, so that Director comes first then Cast? I have added code to hide the unwanted roles/peoples see below:

// print out the list of people in each role
foreach($roles as $rolename => $people) {
    if ($rolename!="Cut" && $rolename!="Producer" && $rolename!="DP" && $rolename!="Writer"){
        if($rolename=="Actor") { $rolename="Cast";};
        echo $rolename . ": " . implode(", ", $people) . "<br />";
    }
}
  • 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-13T02:25:17+00:00Added an answer on June 13, 2026 at 2:25 am

    I would build an array that maps role names to an array of people who filled that role. Possibly something like this:

    $roles = array();
    for($i = 0; $i < $arrayrole1; $i++) {
        $names = explode(", ", $arrayname[$i]);
        $name = $names[1] . " " . $names[0];
        // append the name to the array of people filling the role
        $roles[$arrayrole[$i]][] = $name; 
    }
    
    // print out the list of people in each role
    foreach($roles as $rolename => $people) {
        echo $rolename . ": " . implode(", ", $people) . "<br />";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which will generate two pdf files containing plots to
I have the following PHP code which simply grabs a URL behind HTTP-Basic authentication
I have the following code that grabs all controllers, sorts it, and outputs in
I have the following code in web2py/python: {{for row in db(db.t_problems.id==db.t_problems(request.args(0))).select(): }} Which grabs
I have following code which works for radio buttons but need to be changed
I want to know is below code correct ? I have following code which
I have the following code which definitely returns a proper data result if I
I have the following code which is working, I was wondering if this can
I have the following code which is used to upload large files (~6MB) to
i have the following code which switches some fullscreen-background-images (fadeOut, fadeIn). setInterval(function() { var

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.