'Split string into array based on array of offsets

I have this string, i want to break it into array at specified indexes

Checked this link: separate string in two by given position

but this is regarding breaking it into substring

it is apparent why many are in the favour of the above stance. Another argument

These are the indexes 25, 36, 56

  1. 25th index position will be at starting position of word are

it is apparent why many a

  1. 36th index position will be at starting position of word favour

it is apparent why many are in the f

  1. 56th index position will be at starting position of word stance

it is apparent why many are in the favour of the above s

I want to break the string into array so that resulting string should look like

[0]=>it is apparent why many [1]=>are in the [2]=>favour of the above [3]=>stance. Another.....

Code:

      $substr=[];
$text="It has long been a subject of discussion whether the increase of digital information available online. It seems that universities should only procure digital materials rather than constantly textbooks or not. In this essay, I will explain why using pertinent arguments,  There are myriad of arguments in the favour of my context, and the most conspicuous one lies in the fact that people should be extra careful with their decisions. For example, according to a recent recent survey done by Stand Ford university, 45% people benefit from the above-mentioned notion, whereas 30% people face disadvantages due to it. Hence it is apparent why many are in the favour of the above stance.  Another argument in support of view is that government worldwide has become more active in dealing with this situation. To illustrate, as per a recent academic research carried out by the Australian government; 60% citizen gained immensely from the proposed government reform. They improved their existing scenario tremendously and that paved the way for a better economic future. Therefore, not only will this make people more careful and pragmatic in their approaches, but also will it lead to a better living standard.  From what has been discussed above, it is clear that the benefits of the given topic significantly outweigh the drawbacks. Lastly, in my opinion, it would be wise to say that the role of library has become more obsolete.";
       $offset_arr=['269','308','462','613','654','897'];
       $offset_count=0;
       for($i=0;$i<count($offset_arr);$i++)
       {
        $substr[]=substr($text, $offset_count, $offset_arr[$i]);
       }
       ddh($substr);

Thanks

php


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source