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 490k
  • Answers 490k
  • 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 First of all, it's a really bad idea to use… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer If you are not dead set on using a listbox,… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer killproc will terminate programs in the process list which match… May 16, 2026 at 9:17 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

Related Questions

I'd like to hear your opinions and maybe better suggestions for the following scenario:
Imagine having the following scenario: You need to create a system where the Back
I have the following: XDocument xdoc = XDocument.Load(C:\\myfile.xml); List<Tag> list = new List<Tag>(); foreach
I'm trying out a GStreamer test application, but at runtime the following line fails:
How would you tackle the following storage and retrieval problem? Roughly 2.000.000 rows will
I need advice on what I need to do to make the following two
I am trying to search a text file for a certain pattern. If this
We have created an applet with javafx and it seems that in order to
I'm trying to sell our group on using Mercurial as a source repository rather
I needed some guidance on how to use FlexUnit 4 within Flash Builder, to

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.