What is the difference between explode() and implode() in PHP? PHP में explode() और implode() में क्या अंतर है?
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'| Function | Direction | Signature |
|---|---|---|
| explode() | string to array | explode(separator, string, limit) |
| implode() | array to string | implode(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 से array | explode(separator, string, limit) |
| implode() | array से string | implode(glue, array) |
इंटरव्यू टिप: explode() के optional तीसरे 'limit' पैरामीटर का ज़िक्र करें - positive limit टुकड़ों की संख्या सीमित करता है, negative limit अंत से उतने elements हटा देता है।
Was this answer clear?