الدالة explode() تحوّل النص إلى مصفوفة بتقسيمه عند فاصل تحدده:
$text = "red,green,blue";
$colors = explode(",", $text);
print_r($colors); // [red, green, blue]
المعامل الأول هو الفاصل، والثاني هو النص.
أمثلة شائعة
$words = explode(" ", "Learn with Naw"); // split by space
[$user, $domain] = explode("@", "ali@site.com");
والعكس: implode()
لتحويل المصفوفة إلى نص نستخدم implode():
echo implode(" - ", $colors); // red - green - blue