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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:21:52+00:00 2026-05-16T02:21:52+00:00

I needed suggestions for the following scenario. I have a php variable called $data

  • 0

I needed suggestions for the following scenario.

I have a php variable called $data which holds a lot of information.I am trying to break up the data into fragments using the function explode.
After exploding them into say n fragments, i loop through them and store around 50 lines in array1,50-100 lines in array2 and so on.

   $data = explode( "\n" , $data , 388 );

$x = 27;
while( $x < 72 and $x>=27){$arr["x2"] .= $data[$x] . "\n";
    $x++;}

$x = 72;
while( $x < 117 and $x>=72){$arr["x3"] .= $data[$x] . "\n";
    $x++;}

$x = 117;
while( $x < 162 and $x>=117){$arr["x4"] .= $data[$x] . "\n";
    $x++;}

$x = 162;
while( $x < 207 and $x>=162){$arr["x5"] .= $data[$x] . "\n";
    $x++;}

$x = 207;
while( $x < 252 and $x>=207){$arr["x6"] .= $data[$x] . "\n";
    $x++;}

$x = 252;
while( $x < 297 and $x>=252){$arr["x7"] .= $data[$x] . "\n";
    $x++;}

$x = 297;
while( $x < 342 and $x>=297){$arr["x8"] .= $data[$x] . "\n";
    $x++;}

$x = 342;
while( $x < 387 and $x>=342){
    $arr["x9"] .= $data[$x] . "\n";
    $x++;}

$x = 387;
if(!empty($data[$x])){$arr["x10"] .= $data[$x];
        $x++;}

If i find that $arr[“x10”] is not empty,then i print sample10.pdf.

If the above is not true ,then i check if $arr[“x9”],if this is true then i print sample9.pdf.Like the following

 if(!empty($arr["x10"])){template='https://www.xyz.com/folder/pdf/sample10.pdf';}
 if(!empty($arr["x9"])){template='https://www.xyz.com/folder/pdf/sample9.pdf';}
 if(!empty($arr["x8"])){template='https://www.xyz.com/folder/pdf/sample8.pdf';}
 if(!empty($arr["x7"])){template='https://www.xyz.com/folder/pdf/sample7.pdf';}
 if(!empty($arr["x6"])){template='https://www.xyz.com/folder/pdf/sample6.pdf';}
 if(!empty($arr["x5"])){template='https://www.xyz.com/folder/pdf/sample5.pdf';}
 if(!empty($arr["x4"])){template='https://www.xyz.com/folder/pdf/sample4.pdf';}
 if(!empty($arr["x3"])){template='https://www.xyz.com/folder/pdf/sample3.pdf';}
 if(!empty($arr["x2"])){template='https://www.xyz.com/folder/pdf/sample2.pdf';}
 if(empty($arr["x2"])){template='https://www.xyz.com/folder/pdf/sample.pdf';}

I tried to execute this code,but the code just hangs and it gives me an error.I am trying to write a switch case but am not sure of how to proceed with that.
Any help with the code would be appreciated.
Thanks in advance.

  • 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-16T02:21:52+00:00Added an answer on May 16, 2026 at 2:21 am

    First off, why don’t you try something like this:

    $data = explode( "\n" , $data , 388 );
    
    for ($x = 27; $x < 342; $x++){
       $subarr = (($x-27)/50)+2;
       $arr['x'.$subarr] .= $data[$x] . "\n";
    }
    
    for ($i = 2; $i <= 10; $i++) {
        if (!empty($arr['x'.$i])) {
            template='https://www.xyz.com/folder/pdf/sample'.$i.'.pdf';
        }
    }
    

    … but I’m not sure what you’re trying to do with the “template=” line. It’s not valid PHP, so I don’t know what it’s supposed to do.

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

Sidebar

Ask A Question

Stats

  • Questions 484k
  • Answers 484k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The tools you need are still in beta. You can… May 16, 2026 at 7:19 am
  • Editorial Team
    Editorial Team added an answer Did you try your code above? It should work fine.… May 16, 2026 at 7:19 am
  • Editorial Team
    Editorial Team added an answer Make sure the config file is being copied to the… May 16, 2026 at 7:19 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.