$tokens array does not change at all

血红的双手。 提交于 2019-12-11 06:07:17

问题


If I want to operate with a $tokens array it always happens nothing. An example code:

$input = array("⋃","⋃","a","⋃","h");
$impl = implode($input);
$impl = preg_replace('/⋃{2}/u','$0|',$impl);
preg_match_all('~\X~u', $impl, $tokens);


$akzent = array("´");

$result = array_pop($tokens);

echo print_r($result);

Is it because $tokens is not a normal array?


回答1:


The $tokens here is an array of arrays. That is why you need to access all the matches in the first subarray, $tokens[0]. Modify the part of the code like this:

preg_match_all('~\X~u', $impl, $matches);
$tokens = $matches[0];
$result = array_pop($tokens);

See the PHP demo



来源:https://stackoverflow.com/questions/41027075/tokens-array-does-not-change-at-all

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!