将字符串拆分为字符数组
我正在尝试使用 php 获取余数:
Example:
$string1 ="1477014108152000180343081299001";
$string2 ="1731731731731731731731731731731";
$string1 的每个数字乘以 $string2 的每个数字
$string1 = 1 4 7 7 0 1 4 1 0 8 1 5 2 0 0 0 1 8 0 3 4 3 0 8 1 2 9 9 0 0 1
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
$string2= 1 7 3 1 7 3 1 7 3 1 7 3 1 7 3 1 7 3 1 7 3 1 7 3 1 7 3 1 7 3 1
从字符串的前面开始 总和=1 + 28 + 21 + 7 + 0 + 3 + 4 + 7 + 0 + 8 + 7 + 15 + 2 + 0 +0 + 0 + 7 + 24 + 0 + 21 + 12 + 3 + 0 + 24 + 1 + 14 +27 +9 + 0 + 0 + 1 = 246
Remainder = 246 % 10= 6
我想创建 $string1 数组和$string2,这样我就可以轻松地将每个值相乘。请帮我将 $string1 和 $string2 拆分为数组。
我想要的数组如下:
$array=array('1','7','3','1','7','3','1','7','3','1','7',' 3','1','7', '3','1','7','3','1','7','3','1','7','3','1','7','3 ','1','7','3','1');
I am trying to get remainder value using php:
Example:
$string1 ="1477014108152000180343081299001";
$string2 ="1731731731731731731731731731731";
Each digit of $string1 is multiplied by each digit of $string2
$string1 = 1 4 7 7 0 1 4 1 0 8 1 5 2 0 0 0 1 8 0 3 4 3 0 8 1 2 9 9 0 0 1
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
$string2= 1 7 3 1 7 3 1 7 3 1 7 3 1 7 3 1 7 3 1 7 3 1 7 3 1 7 3 1 7 3 1
Starting from the front of the string
Sum=1 + 28 + 21 + 7 + 0 + 3 + 4 + 7 + 0 + 8 + 7 + 15 + 2 + 0 +0 + 0 + 7 + 24 + 0 + 21 + 12 + 3 + 0 + 24 + 1 + 14 +27 +9 + 0 + 0 + 1 = 246
Remainder = 246 % 10= 6
I want to create array of $string1 and $string2, so that I can easily multiply each value. Please help me to split $string1 and $string2 in to array.
I want array as below:
$array=array('1','7','3','1','7','3','1','7','3','1','7','3','1','7','3','1','7','3','1','7','3','1','7','3','1','7','3','1','7','3','1');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 str_split
Use str_split
您可以访问字符串字符作为数组元素:
you can access to string characters as to array elements:
据我了解,您要实现的目标是,在处理之前没有理由分割字符串
或(仅查看其余部分)
最后一个绝对是首选,因为您可以假设总和将增长非常大的
As far as I understand, what you are going to achieve, there is no reason to split the strings, before processing
or (only looking at the remainder)
The last one is definitly prefered, because you can assume, that the sum will grow very large
您可以使用 preg_match_all 来做到这一点:
You can do this using preg_match_all: