<?php $names = [ "Ayush" , "Vaibhav", "Shivam", "Hacker", "Topper", "ABCD", "NameR", "Tammi", "Colgate", "Britney"//, "Bra"//, "Kisser" ]; $addthis = 'ADDTHIS'; $result = array(); foreach (array_chunk($names, 3) as $chunk) { // iterate over each chunk foreach ($chunk as $element) { $result[] = $element; } // Now push your extra element at the end of the 3 elements' set $result[] = $addthis; } var_export($result);
You have javascript disabled. You will not be able to edit any code.