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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:07:36+00:00 2026-05-20T00:07:36+00:00

i am so stuck , please someone help if you have 2 min. i

  • 0

i am so stuck , please someone help if you have 2 min.

i have a foreach where I get values from session something like

foreach ($result as $i => $item ) {

         $values_array  = explode("\n",$get_widths); // outputs Array ( [0] => 120 [1] => 180) 
         // here I need to echo the value from the array but only ONCE
}

the issue is that this is used by 2 or more items and array outputs gets repeated every time , so if 2 items i get
Array ( [0] => 120 [1] => 180) Array ( [0] => 120 [1] => 180) or
120 120
instead

120 180

for actual code see here

<?php
foreach ($list as $i => &$item){
    $i=0;
    $is_group                   = $item_params->get('is_group');    
    $group_widths               = $item_params->get('group_widths');    
    $group_widths_array         = explode("\n",$group_widths);

    if($is_group == 1){

        echo $group_widths_array[$i];
    }



}
?>

please note I cant move outside the foreach. 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-05-20T00:07:36+00:00Added an answer on May 20, 2026 at 12:07 am

    I am completely missing the point of this loop…

    You are iterating over an array, assigning the key to $i and the value to $item but then you set $i to 0, echoing $group_widths_array[0] every time your condition is met and $item you don´t use at all…

    That can´t be right, can it?

    Anyway, it seems to me that the reason that your output is repeated is that you output $group_widths_array[0] every time and $is_group is the same on every iteration.

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

Sidebar

Related Questions

I am stuck with some TouchXML code. Please help. I have the following code
Please help, I am stuck here --- irb> a = line of text\n line
I have a java project. The working folder from someone else's Eclipse project (It
Could someone please help me with the code for below requirement or scenarios...I achieved
I am hoping someone can help me with a problem I'm stuck with. I
I'm new here and I'm very stuck. I need help. Hopefully someone can tell
hope someone can help me on this as been stuck for hours. I am
I'm a developer and I suck at SQL:) Please help me out here. I'd
First time Stack Overflow poster. Please bear with me! :) I have a set
Kinda stuck here... I have an application with lets say 5000 rows of data

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.