3v4l.org

run code in 300+ PHP versions simultaneously
<?php $mediaArray ='Facebook,Twitter,Twitch,'; $otherMedia = 'House'; //convert string to array $socialArray = explode(',', $mediaArray); //declare some variables to be used later $andwhere = ''; $bp = ''; $socialmarray = ''; //get every value from array of social media foreach($socialArray as $socialmedia){ $socialmarray .=$socialmedia.','; $andwhere .= " AND socialmedianame=?"; $bp .='s'; } //test strings $wheres = $andwhere;//AND socialmedianame=? AND socialmedianame=? AND socialmedianame=? $bip = $bp.'s';//ssss $validarayy = rtrim($socialmarray,','); //Facebook,Twitter,Twitch $socialmarray2 = explode(',', $validarayy); var_dump($socialmarray2);
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1 - 8.4.2
array(3) { [0]=> string(8) "Facebook" [1]=> string(7) "Twitter" [2]=> string(6) "Twitch" }

preferences:
85.35 ms | 407 KiB | 5 Q