Programming Tutorials

(追記) (追記ここまで)

All possible substrings in a String in PHP

By: Lukman in PHP Tutorials on 2011年11月17日 [フレーム]

The following code uses arrays to retrieve all possible substrings in a given string in PHP.

function get_all_substrings($input, $delim = '') {
 $arr = explode($delim, $input);
 $out = array();
 for ($i = 0; $i < count($arr); $i++) { for ($j = $i; $j < count($arr); $j++) { $out[] = implode($delim, array_slice($arr, $i, $j - $i + 1)); } } return $out; } $subs = get_all_substrings("a b c", " "); print_r($subs);



(追記) (追記ここまで)


Add Comment

JavaScript must be enabled for certain features to work
* Required information
1000

Comments

No comments yet. Be the first!
(追記) (追記ここまで)
(追記) (追記ここまで)

AltStyle によって変換されたページ (->オリジナル) /