I know this question was asked before, and I checked most of them. I couldn't get rid of this error. I keep getting Notice: Array to string conversion in C:\wamp64\www\test.php on line 23
. Line 23 is this line: $aRanges[] = $aGroup[0] . '-' . $aGroup[count($aGroup)-1];
I'd appreciate your help. thank you.
$sql = "SELECT Rab, Rbc, Rcd, Rde FROM datatb";
$result = $conn->query($sql);
//Fetching all the results to array
while(($mData[] = mysqli_fetch_assoc($result)) || array_pop($mData));
function GetRanges( $mData ) {
$mData = array_unique( $mData );
sort( $mData );
$aGroups = array();
for( $i = 0; $i < count( $mData ); $i++ ) {
if( $i > 0 && ( $mData[$i-1] == $mData[$i] - 1 ))
array_push( $aGroups[count($aGroups)-1], $mData[$i] );
else
array_push( $aGroups, array( $mData[$i] ));
}
$aRanges = array();
foreach( $aGroups as $aGroup ) {
if( count( $aGroup ) == 1 )
$aRanges[] = $aGroup[0];
else
$aRanges[] = $aGroup[0] . '-' . $aGroup[count($aGroup)-1];
}
return $aRanges;
}
print_r( GetRanges( $mData ));