logo CodeStepByStep logo

array_split

Language/Type: PHP arrays array traversals

Write a function named array_split that accepts an array of integers as a parameter and returns a new array twice as large as the original, replacing every integer from the original array with a pair of integers, each half the original.

For example, if a variable named $arr refers to an array storing the values [18, 7, 4, 24, 11], the call of array_split($arr) should return a new array containing [9, 9, 3.5, 3.5, 2, 2, 12, 12, 5.5, 5.5]. (The number 18 is split into the pair 9, 9, the number 7 is split into 3.5, 3.5, the number 4 is split into 2, 2, the number 24 is split into 12, 12 and the number 11 is split into 5.5, 5.5.)

Function: Write a PHP function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.