在PHP中,我有一个包含所有字符串的变量数组.存储的某些值是带逗号的数字字符串.
我需要的:
一种从字符串中修剪逗号的方法,只对数字字符串执行此操作.这并不像看起来那么简单.主要原因是以下失败:
$a = "1,435";
if(is_numeric($a))
$a = str_replace(',', '', $a);
Run Code Online (Sandbox Code Playgroud)
这$a = "1435"是因为数字而失败.但$a = "1,435"不是数字.因为我得到的一些字符串将是带逗号的常规句子,所以我不能在每个字符串上运行字符串替换.
我试图了解Twig如何通过AJAX加载模板.从他们的网站上可以看出如何加载模板(http://twig.sensiolabs.org/doc/api.html)
echo $twig->render('index.html', array('the' => 'variables', 'go' => 'here'));
Run Code Online (Sandbox Code Playgroud)
但是如何才能为AJAX调用呢?你怎么告诉Twig你想要'渲染'只是index.html的一部分的东西......而不是重新加载整个页面?我查看了Twig唯一的Ajax示例(http://twig.sensiolabs.org/doc/recipes.html),但这并未解释Twig如何知道您要更改的页面的哪个部分.假设您的Ajax调用导致页面内容更新.我只需要一个简单的例子,比Twig的食谱页面更多.
在mongo中,我正在尝试查询id以某个数字结尾的用户.这个数字是我传入的参数.
所以,如果我有4个用户[3544,42345,66452,7348],我怎么能查询和刚刚得到用户7348如果我是用户的ID在8结束只是感兴趣.
我在这里看了一下,但找不到对此有用的东西:
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions
更新:执行此操作是PHP,期望值是int,而不是字符串.我的where子句如下所示:$ where = array('uid'=>'/ 8 $ /');
给定一个数组,我想要一个扁平版本的数组键.每个数组键都需要数组的"路径",到那一点,附加一个下划线.
一个例子解释了这一点.
$arr = array("location"=>0,"details"=>array("width"=>0,"height"=>0,"level"=>array("three"=>0)));
function answer($arr) {....}
Run Code Online (Sandbox Code Playgroud)
答案函数会返回:
array("location","details_width","details_height","details_level_three");
Run Code Online (Sandbox Code Playgroud)
更新:
这是正在进行的工作.它将接受一个数组并返回数组键,但没有深度:
function recursive_keys($input)
{
$output = array_keys($input);
foreach($input as $sub){
if(is_array($sub)){
$output = array_merge($output, recursive_keys($sub));
}
}
return $output;
}
Run Code Online (Sandbox Code Playgroud)