I'm trying to solve one simple task and on first look it's working.Any advice on how I can optimize this code will be appreciated.A quick description of the task would be:You have a file from which you read the integers.The first line has two values:The array widthThe number of test casesThe second line has actual array values.After that, you have \$N\$ rows all containing the array range which should be checked.\$N =\$ the number of test cases.Here's a link to my code<?php$handle = fopen(php://stdin, r);$getFirstRow = fgets($handle);$firstrow = explode( , $getFirstRow);$firstrow1 = intval($firstrow[0]);$firstrow2 = intval($firstrow[1]);$getString = fgets($handle);for ($z=0;$z<$firstrow2;$z++){$getRange = fgets($handle);$getRagearr = explode( , $getRange);$i=intval($getRagearr[0]);$j=intval($getRagearr[1]);$arrResult = array();$lane = explode( , $getString);for ($p=$i;$p<=$j;$p++){array_push($arrResult, $lane[$p]);}$result = min($arrResult);echo $result.PHP_EOL;}
Finding minimum array integer
php;algorithm;programming challenge
You should indent your code properly to make it more readable.Posting PHP on JSFiddle is apocalyptic insanity a bad idea. JSFiddle is for JavaScript.Use IDEOne for PHP Instead.Your use of whitespace could be improved. for ($z=0;$z<$firstrow2;$z++)into: for ($z = 0; $z < $firstrow2; $z++)Your variable naming is shortened, sometimes confusing, and flat out bad practice in places.Transform them from lowercase to camelCase.You don't even use $firstrow1, remove it.$getRagearr sounds like a pirate themed narcotic. Perhaps $getRangeArray would be much clearer.$j=intval($getRagearr[1]): what's wrong with good ole' fashioned int()?'This is the result of all my suggestions:$handle = fopen(php://stdin, r);$getFirstRow = fgets($handle);$firstRowArray = explode( , $getFirstRow);$numOfTestCases = int($firstRow[1]);$getString = fgets($handle);for ($i = 0; $i < $numOfTestCases; $i++) {    $getRange = fgets($handle);    $getRangeArray = explode( , $getRange);    $arrayWidth = int($getRangeArray[0]);    $arrayLength = int($getRangeArray[1]);    $arrayResult = array();    $lane = explode( , $getString);    for ($currentPos = $arrayWidth; $currentPos <= $arrayLength; $currentPos++) {        array_push($arrayResult, $lane[$currentPos]);    }    $result = min($arrayResult);    echo $result.PHP_EOL;}Other than that, your code looks well-structured.