PHP Basics



21. What is GD in PHP?  

The GD library is used for image manipulating and graphics drawing tools library.


22. What is the main difference between require() and require_once()?  

The require_once() statement is identical to require() except PHP will check if the file has already been included, and if so, not include (require) it again.


23. How to pretty print in PHP?  

we can use print_r()
    


24. How to export data to an excel file?  

Simple Example :

// Create your database query
$query = "SELECT * FROM myDataTable";  

// Execute the database query
$result = mysql_query($query) or die(mysql_error());

// Instantiate a new PHPExcel object
$objPHPExcel = new PHPExcel(); 
// Set the active Excel worksheet to sheet 0
$objPHPExcel->setActiveSheetIndex(0); 
// Initialise the Excel row number
$rowCount = 1; 
// Iterate through each result from the SQL query in turn
// We fetch each database result row into $row in turn
while($row = mysql_fetch_array($result)){ 
    // Set cell An to the "name" column from the database (assuming you have a column called name)
    //    where n is the Excel row number (ie cell A1 in the first row)
    $objPHPExcel->getActiveSheet()->SetCellValue('A'.$rowCount, $row['name']); 
    // Set cell Bn to the "age" column from the database (assuming you have a column called age)
    //    where n is the Excel row number (ie cell A1 in the first row)
    $objPHPExcel->getActiveSheet()->SetCellValue('B'.$rowCount, $row['age']); 
    // Increment the Excel row counter
    $rowCount++; 
} 

// Instantiate a Writer to create an OfficeOpenXML Excel .xlsx file
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel); 
// Write the Excel file to filename some_excel_file.xlsx in the current directory
$objWriter->save('some_excel_file.xlsx');




25. How to Get number of rows in result ?  

mysql_num_rows — Get number of rows in result


26. PHP check if a variable is a number?  

We can use is_numeric() to check if it is a number or not.


.Net Interview Question

PHP Interview Question

Java Interview Question

AngularJS Interview Questions