Friday, 30 January 2015

Include Methods



Two different methods for including files:



Include():


In php include() method use for including multiple files,its takes all content of file and copies it in the specified.

syntax for include() method as below:

<?php

include 'file_name.php';

?>


file_name.php means path of file



Include_once():


Include_once is similar as include() method ,only different is that if the code from a file has already been included, it will not be included again

syntax for include_once method as below:

<?php

include_once 'file_name.php';

?>






Thursday, 29 January 2015

Explode Vs Implode

Explode

 explode() function splits a string into  components, based on a  delimiter given by users, and create an array according to  delimiters. 

<?php

// define CSV string
$mystring= 'val1, val2val3'; 

// split into individual words 
$myarray = explode(', ', $mystring); 

print_r($myarray); 

//print output Array ( [0] => val1 [1] => val2 [2] => val3 )
?>



Implode

 implode() function, which creates a single string from all the elements of an array by joining them together with a  delimiter given  by users. eg:




<?php

// define array
$myarray= array ('val1', 'val2'); 

// join into single string with ' - ' 

$mystring= implode(' - ', $colors); 

echo $mystring; 


//print output val1 - val2
?>