Introduction

Hello and welcome to our exciting exploration of PHP string manipulation! Today's lesson is particularly interesting: you will learn how to access characters from a string following a distinctive pattern using PHP. Our presentation is both comprehensive and concise, allowing you to master the concept quickly. Let's get started!

Task Statement

Imagine this: You receive a string, from which you need to extract characters, but the sequence in which you select them diverges from the norm. You start with the first character, then select the last character, move to the second character, then choose the second-to-last character, and continue this pattern until there are no characters left. Quite a mind-bender, isn't it?

Here's what we mean:

You are required to craft a PHP function, solution($inputString), within a PHP script. This function takes $inputString as a parameter, a string of lowercase English alphabet letters ('a' to 'z'), with a length ranging between 1 to 100 characters. The function then returns a new string, fashioned from the input string, but with characters selected in the pattern we described above.

For example, if the $inputString is "abcdefg", the function should return "agbfced".

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal