本文介绍了必须从某些字符串添加prevent美元符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个数组;
Array (
[0] => (
[1] => he
[2] => +
[3] => is
[4] => +
[5] => genius
[6] => )
[7] => *
[8] => and
[9] => /
[10] => clever )
这是possibe把美元符号在阵列中的每个字母数字字符串之前,该链接是在这里:
Adding在阵列中的每个字符串之前,美元符号?
现在,是否有可能prevent美元符号被添加到一个特定的字符串,例如,如果有一句话她,谁,或者他们在阵列比不应该被添加到这些字符串美元符号?
Now, Is it possible to prevent dollar sign to be added to a certain strings, for example if there is a word she, who or they in array than dollar sign should not be added to these strings?
推荐答案
去了你的旧code,我修改的:
Going off of your old code, I amended it:
$noappend = array("she","who","they"); // add more
// $arr is your array as defined in your question
foreach ($arr as &$val) {
//OR if (ctype_alpha($val[0])) {
if (ctype_alpha($val) && !in_array($val, $noappend)) {
$val = '$' . $val;
}
}
var_dump($arr);
这篇关于必须从某些字符串添加prevent美元符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!