我的php问题如下:
我有这个字符串:$days="Monday* Tuesday* Wednesday*"
我想创建一个这样的数组:$d[1]="Monday"; $d[2]="Tuesday"; $d[3]="Wednesday"
我感觉到解决方案通过了,explode(*, $days)
但我无法更进一步
感谢您的帮助 :)
$days="Monday* Tuesday* Wednesday*";
$d=explode('* ', $days);
或者
$days="Monday* Tuesday* Wednesday*";
$d=explode(' ', str_replace('*','',$days));
用于排除最后一个单词末尾的“*”。
explode('* ', trim($days, '*'));
你应该使用:
explode("* ", $days)
但是国际海事组织,我会使用这样的昏迷:
$days = "Monday,Tuesday,Wednesday";
$days = explode(",", $days);
echo $days[0]; // => Monday
echo $days[1]; // => Tuesday
$days="Monday* Tuesday* Wednesday*";
$exploded = explode('* ',substr($days, 0, -1));
print_r($exploded);
输出:
Array
(
[0] => Monday
[1] => Tuesday
[2] => Wednesday
)
<?php
$days = 'Monday* Tuesday* Wednesday*';
$d = array_filter(explode('* ', $days));