Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 4 of 10 · Arrays & String Functions
Interview question

What is the difference between explode() and implode() in PHP? PHP में explode() और implode() में क्या अंतर है?

Answer

explode() splits a string into an array using a delimiter. implode() (alias: join()) joins array elements into a single string using a glue string. They are exact opposites.

$csv = 'Raj,Amit,Sara';
$names = explode(',', $csv);
// ['Raj', 'Amit', 'Sara']

$joined = implode(' | ', $names);
// 'Raj | Amit | Sara'
FunctionDirectionSignature
explode()string to arrayexplode(separator, string, limit)
implode()array to stringimplode(glue, array)

Interview tip: Mention the optional third 'limit' parameter of explode() - a positive limit caps the number of pieces, and a negative limit removes that many elements from the end.

explode() string को delimiter से array में तोड़ता है। implode() (alias: join()) array elements को glue string से एक string में जोड़ता है। ये बिल्कुल विपरीत हैं।

$csv = 'Raj,Amit,Sara';
$names = explode(',', $csv);
// ['Raj', 'Amit', 'Sara']

$joined = implode(' | ', $names);
// 'Raj | Amit | Sara'
FunctionदिशाSignature
explode()string से arrayexplode(separator, string, limit)
implode()array से stringimplode(glue, array)

इंटरव्यू टिप: explode() के optional तीसरे 'limit' पैरामीटर का ज़िक्र करें - positive limit टुकड़ों की संख्या सीमित करता है, negative limit अंत से उतने elements हटा देता है।

Was this answer clear?