note 102928 added to function.preg-split
| From: | tkama at bk dot ru | Date: | Tue, 15 Mar 2011 12:06:08 +0000 |
| Subject: | note 102928 added to function.preg-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-177885@lists.php.net to get a copy of this message | ||
This mistake look like a paradox, but that's what I see:
Example 1:
$str = 'hypertext language programming';
$chars = preg_split('/ /', $str, -1, PREG_SPLIT_OFFSET_CAPTURE);
foreach($chars as $k=>$v){
$chars2[] = $chars[$k][0];
}
print_r($chars2);
Example 2:
$str = 'hypertext language programming';
$chars = preg_split('/ /', $str);
print_r($chars);
First example works faster then second. Why so?
----
Server IP: 69.147.83.197
Probable Submitter: 89.236.237.142
----
Manual Page -- http://www.php.net/manual/en/function.preg-split.php
Edit -- https://master.php.net/note/edit/102928
Del: integrated -- https://master.php.net/note/delete/102928/integrated
Del: useless -- https://master.php.net/note/delete/102928/useless
Del: bad code -- https://master.php.net/note/delete/102928/bad+code
Del: spam -- https://master.php.net/note/delete/102928/spam
Del: non-english -- https://master.php.net/note/delete/102928/non-english
Del: in docs -- https://master.php.net/note/delete/102928/in+docs
Del: other reasons-- https://master.php.net/note/delete/102928
Reject -- https://master.php.net/note/reject/102928
Search -- https://master.php.net/manage/user-notes.php