帮忙解决下数组的有关问题!(初学者问.)
Jun 13, 2016 pm 01:46 PM
帮忙解决下数组的问题!(菜鸟问..)
就是说现在一个变量$p的数据是221,567,568,569,572,573,1408,1723,1724,1725,1726,1727,1728,1729,1730,1731,1732,1733,2586,13587
这是echo出来的...
现在要怎么定义一个数组..把这些数据一个一个放到数据里面去...
$s[0]=221,$s[1]=567............
请各位大哥帮帮忙啊!
------解决方案--------------------
$p= "221,567,568,569,572,573,1408,1723,1724,1725,1726,1727,1728,1729,1730,1731,1732,1733,2586,13587 "
$s = explode( ', ', $p);
print_r($s);
------解决方案--------------------
$p = '221,567,568,569,572,573,1408,1723,1724,1725,1726,1727,1728,1729,1730,1731,1732,1733,2586,13587 ';
$s = explode( ', ',$p);
print_r($s);
-------------------
---------- PHP调试 ----------
Array
(
[0] => 221
[1] => 567
[2] => 568
[3] => 569
[4] => 572
[5] => 573
[6] => 1408
[7] => 1723
[8] => 1724
[9] => 1725
[10] => 1726
[11] => 1727
[12] => 1728
[13] => 1729
[14] => 1730
[15] => 1731
[16] => 1732
[17] => 1733
[18] => 2586
[19] => 13587
)
输出完成 (耗时: 0 秒) - 正常终止
------解决方案--------------------
$p= "221,567,568,569,572,573,1408,1723,1724,1725,1726,1727,1728,1729,1730,1731,1732,1733,2586,13587 "
print_r(split( ", ",$p));
这样也行..
------解决方案--------------------
$p= "221,567,568,569,572,573,1408,1723,1724,1725,1726,1727,1728,1729,1730,1731,1732,1733,2586,13587 ";
$s=explode( ", ",$p);
-------------
echo $s;//输出array
-------------
这样就把$p中的数据存入数组$s中了:$s[0]=221;$s[1]=567.........$[19]=13587;
------解决方案--------------------
$p= "221,567,568,569,572,573,1408,1723,1724,1725,1726,1727,1728,1729,1730,1731,1732,1733,2586,13587 "
$s = explode( ', ', $p);
print_r($s);
------解决方案--------------------
...楼上的
explode还有这鸟函数 我还在用split呢
我日 php就是恶心 同一功能N个函数 不累死人
顺便问下大家 2000-01-09 20:30:20
怎么输出2000-01-09
难道用explode分割 " "吗?
有象asp中的datevalue 类似的函数吗?

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the differences between Huawei GT3 Pro and GT4?

Fix: Snipping tool not working in Windows 11

How to Fix Can't Connect to App Store Error on iPhone

How to use PHP explode function and solve errors

Split and merge strings using the explode and implode functions

Common errors and solutions when using the explode function in PHP
