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

  • Home
  • SEARCH
  • 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 6476251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:48:08+00:00 2026-05-25T06:48:08+00:00

Really struggling with this one: I have an existing foreach, containing an if loop

  • 0

Really struggling with this one:

I have an existing foreach, containing an if loop looking for specific values. But I also have an array containing values which if found should have the same action taken as the specific values:

Here I loop through and when values are between 5 and 9, I take the value of $datacolvalue and add it to another array as an integer rounded to 2 decimal places.

Otherwise, add it as a string, untouched.

$data_row = array();
$count = 1;
foreach ($row->COLUMN as $datacolvalue){

    if($count > 4 && $count < 10)
        $data_row[] = round((float)$datacolvalue, 2);
    else
        $data_row[] = (string)$datacolvalue;

      $count++;
}

What I want to do, is is do the same thing $data_row[] = round((float)$datacolvalue, 2); if the value of $count is in a static array named $array_to_round which looks like this (values are different each time the php is run:

array(12,34,56,78);

I though about adding a foreach inside the “else” condition but I cannot get my head around it. Is a for/while/loop the answer?

In a nutshell, for each $datacolvalue, if $count is (> 4) and (< 10) OR is present in the $array_to_round array place in array as int and round, otherwise, place it as a string.

  • 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-25T06:48:09+00:00Added an answer on May 25, 2026 at 6:48 am

    Use in_array to check if the value exists in the other array, then add it as necessary,

    I would also store the rounded value if you plan to use it as a check and a setter.

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

Sidebar

Related Questions

I am really struggling with this one. I have Google'd this and tried most
I'm really struggling to get this to work in xcode 4. I have one
Really been struggling with this one for some time now, i have many text
Hey, I'm really struggling with this one. I'am trying to port a small piece
really struggling with this one. I've recently setup a bash shell script to extract,
I have been struggling with this for a while and could really use some
I am really struggling with this one. Below is an image of a layout
Hi I am really struggling with this one. I am developing with Google Analytics
Sorry if this sounds stupid but I'm really new to LiftWeb and just struggling
OK i am really struggling with this! I know had to add an image

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.