Issues when using multiple if statements in php
<p>I needed suggestions for the following scenario.</p>

<p>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.</p>

<pre><code>   $data = explode( "\n" , $data , 388 );

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

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

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

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

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

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

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

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

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

<p>If i find that $arr["x10"] is not empty,then i print sample10.pdf.</p>

<p>If the above is not true ,then i check if $arr["x9"],if this is true then i print sample9.pdf.Like the following </p>

<pre><code> 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';}
</code></pre>

<p>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.</p>
