在PHP中爆炸单个变量 [英] explode single variable in php
本文介绍了在PHP中爆炸单个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我在php中拥有的东西:
Here is what i have in php :
我需要爆炸给定的变量
$a = "hello~world";
我需要爆炸为
$first = "hello";
$second = "world";
我该怎么做??
这是我到目前为止尝试过的.
Here is what i have tried so far.
<?php
$str = "a~b";
$a = (explode("~",$str));
$b = (explode("~",$str));
echo explode('.', 'a.b');
?>
我知道我做错了.我的错误是什么,我该如何解决?
I know i did wrong. What is my mistake and how can i fix this ?
推荐答案
如果您知道要获取的变量数(在本例中为2),则可以直接将它们分配给list
:
If you know the number of variables you're expecting to get back (ie. 2 in this case) you can just assign them directly into a list
:
list($first, $second) = explode('~', $a);
// $first = 'hello';
// $second = 'world';
这篇关于在PHP中爆炸单个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文