I have a PHP variable $MostRecentQuestionType
whose value is SimplifyingFractions
. I want to print Simplifying Fractions
, so I tried the following, but it returns Array ( [0] => Simplifyin [1] => Fractions )
我有一个PHP变量$ MostRecentQuestionType,其值为SimplifyingFractions。我想打印简化分数,所以我尝试了以下,但它返回Array([0] => Simplifyin [1] =>分数)
$MostRecentQuestionType = $data['MostRecentQuestionType'];
$MostRecentQuestionTypeExploded = preg_split('/.(?=[A-Z])/',$MostRecentQuestionType);
print_r($MostRecentQuestionTypeExploded);
How do I extract the words from this array?
如何从此数组中提取单词?
Side note: I know people are going to attack me for not doing my research; I've tried but I don't quite have the vocab to look up the solution. I've tried converting array to string
and similar searches, but the results don't address this question. My searching has led to me to preg_replace
, str_replace
, toString()
, among others, but nothing seems to help. I feel like I'm getting hung up on something that has a very easy solution.
旁注:我知道人们会因为没有做我的研究而攻击我;我已经尝试了,但我没有足够的词汇来查找解决方案。我已经尝试将数组转换为字符串和类似的搜索,但结果没有解决这个问题。我的搜索导致我preg_replace,str_replace,toString()等,但似乎没有任何帮助。我觉得我已经陷入了一个非常简单的解决方案。
2 个解决方案
#1
2
Something like this:
像这样的东西:
<?php
$MostRecentQuestionType = "SimplifyingFractions";
$MostRecentQuestionTypeExploded = preg_split('/(?=[A-Z])/',$MostRecentQuestionType);
print(implode($MostRecentQuestionTypeExploded," "));
You could also cut out the middle man by doing:
你也可以通过以下方式切断中间人:
<?php
$MostRecentQuestionType = "SimplifyingFractions";
$MostRecentQuestionTypeExploded = preg_replace('/(?=[A-Z])/'," ",$MostRecentQuestionType);
print($MostRecentQuestionTypeExploded);
#2
0
Instead of your print_r command, you can do this :
您可以执行以下操作,而不是print_r命令:
foreach($MostRecentQuestionTypeExploded as $value) { print($value." ");}
#1
2
Something like this:
像这样的东西:
<?php
$MostRecentQuestionType = "SimplifyingFractions";
$MostRecentQuestionTypeExploded = preg_split('/(?=[A-Z])/',$MostRecentQuestionType);
print(implode($MostRecentQuestionTypeExploded," "));
You could also cut out the middle man by doing:
你也可以通过以下方式切断中间人:
<?php
$MostRecentQuestionType = "SimplifyingFractions";
$MostRecentQuestionTypeExploded = preg_replace('/(?=[A-Z])/'," ",$MostRecentQuestionType);
print($MostRecentQuestionTypeExploded);
#2
0
Instead of your print_r command, you can do this :
您可以执行以下操作,而不是print_r命令:
foreach($MostRecentQuestionTypeExploded as $value) { print($value." ");}