[英]splitting a string every 4 characters and then put those into new variables?
How would i split a string every 4 characters and then have every 4 characters put into a separate variable so i can do other stuff with each individual 4 characters?我将如何每 4 个字符拆分一个字符串,然后将每 4 个字符放入一个单独的变量中,以便我可以对每个单独的 4 个字符执行其他操作?
Well, I don't really see you putting each of them in a different variable, because then you'll have like 10 variables:好吧,我真的没有看到您将它们中的每一个都放在不同的变量中,因为那样您将拥有大约 10 个变量:
$var1 = ...;
$var2 = ...;
$var3 = ...;
But you could use the str_split
function as following:但是您可以使用
str_split
function 如下:
$variable = str_split($origionalvar, 4);
it will create an array, which you can access:它将创建一个数组,您可以访问该数组:
$variable[0]
to $variable[sizeof(variable)]
$variable[0]
到$variable[sizeof(variable)]
If you don't know about arrays, you really should read up on those.如果您不了解 arrays,您真的应该阅读这些内容。 They are really great if you want to store a lot of similar information in an object and you don't want to create a new variable for it every time.
如果您想在 object 中存储大量类似信息并且您不想每次都为其创建新变量,那么它们真的很棒。 Also you can loop over them very easily and do some other great stuff with them.
你也可以很容易地循环它们并用它们做一些其他很棒的事情。
I assume you probably googled this question a bit too.我想你可能也用谷歌搜索了这个问题。 You must have come across http://php.net/manual/en/function.str-split.php .
你一定遇到过http://php.net/manual/en/function.str-split.php 。 Did you see this page, and if you did, did you have some trouble with it.
你看到这个页面了吗,如果你看到了,你是不是遇到了一些麻烦。 If so perhaps we can help you reading the documentation properly.
如果是这样,也许我们可以帮助您正确阅读文档。
Have a look at the str_split
function.看看
str_split
function。 The PHP manual will tell you all you need to know. PHP 手册将告诉您您需要知道的一切。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.