Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Explain the difference of extract() ,explode() and implode() ?

user-image
Question added by Julfkar Moh Umar , Sr. Software Engineer , Aakash Edutech Private Limited
Date Posted: 2016/01/11
Abdul Rehman Anwer
by Abdul Rehman Anwer , Developer , Creative Advertising

In PHP these3 builtin functions are related to array. So I'll try to give you an idea about three of these functions below.

1 : extract() .. This function takes array and converts them into local variables from array keys. here is an example.

$cities = array( 'a' => 'Dubai', 'b' => 'Islamabad', 'c' => ' Mambai' );

extract( $cities );

echo $a;

echo '<br />';

 

echo $b;

echo '<br />';

 

echo $c;

echo '<br />';

The Output :

Dubai

Islamabad

Mambai

2:  implode() .. This function returns a string from the elements of an array. assuming that we are working with the above array.

echo implode( $cities )'

out put will be :

Dubai Islamabad Mambai.

3 : explode() .. This function somewhat works against implode(). and it breaks a strings into an array.

$string = 'Hello Bayt, I am a string';

print_r (explode(" ",$string));

The Output:

array( [0] => Hello [1] => Byat, [2] => I [3] => am [4] => a [5] => string )

Implode: to collapse inward in a very sudden and violent way

Explode:to expand with force and noise because of rapid chemical change or decomposition

Extract to get, pull, or draw out, usually with special effort, skill, or force

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.