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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:43:51+00:00 2026-06-07T17:43:51+00:00

what do i need to change for my codes? the echo is just 1

  • 0

what do i need to change for my codes?
the echo is just 1 letter m

this is my code :

$string = 'mars@email.com,123,12,1|art@hur.com,321,32,2';

$output = array();

foreach (explode('|', $string) as $key => $person) {
    $output[] = array(
        'email'   =>    $person[0],
        'score'   =>    $person[1],
        'street'  =>    $person[2],
        'rank'    =>    $person[3]
    );
    echo $output[0]['email']; 
}

OUTPUT : m

the output should be:

$email1  = mars@email.com
$score1  = 123
$street1 = 12
$rank1   = 1

$email2  = art@hur.com
$score2  = 321
$street2 = 21
$rank2   = 2

is it possible to do this code to output the email1 and email2?
is my code correct or do i need to change something?

thank you.

  • 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-07T17:43:53+00:00Added an answer on June 7, 2026 at 5:43 pm

    You need to use a nested loop; the first to iterate over the pipe delimited data and the second for the comma delimited entries.

    $string = 'mars@email.com,123,12,1|art@hur.com,321,32,2';
    
    $entries = explode('|', $string);
    foreach ($entries as $i => $entry) {
        $parts = explode(',', $entry, 4);
        if (count($parts) < 4) {
            // not enough parts, throw an error or something
        }
        printf('$email%d  = %s%s', $i+1, $parts[0], PHP_EOL);
        printf('$score%d  = %s%s', $i+1, $parts[1], PHP_EOL);
        printf('$street%d = %s%s', $i+1, $parts[2], PHP_EOL);
        printf('$rank%d   = %s%s', $i+1, $parts[3], PHP_EOL);
        echo PHP_EOL;
    }
    

    Example here – http://codepad.viper-7.com/82HbtT

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

Sidebar

Related Questions

I need to change a piece of code which includes this: string.indexOf(bc) How can
I need to change this code to cpp code This is the c# code
I have this working code, but now i need to be able to change
As good as the Java API is, I need to change the code of
I need to change ASPxGridView SettingsLoadingPanel dynamically (from code behind if is possible). For
I need to change the background colour of a button using C# code (Visual
I have code that needs to loop and it will need to change the
I need to change the + to - when toggled. The code is set
I need to make javascript code to swap images with option change. Here is
UPDATE2: i tried this piece of code, but still no echo, i valued my

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.