$str = '1000,10.00,10000.00@500,5.00,2500.0';
$ex = explode('@',$str);
//result = Array ( [0] => 1000,10.00,10000.00 [1] => 500,5.00,2500.00 );
$ex2 = explode(',',$ex);
//result need Array ( [0] => 1000, [1] => 500, [2] => 2500);
答案 0 :(得分:1)
您可以使用此方法:
<?php
$str = '1000,10.00,10000.00@500,5.00,2500.0';
$arrayResult = [];
$arrayData = explode('@',$str);
foreach($arrayData as $sing){
$arrayResult[] = explode(",",$sing);
}
echo "<pre>";
print_r($arrayResult);
echo "</pre>";
答案 1 :(得分:0)
explode()
返回一个数组,因此$ex
将是您需要遍历/遍历的数组:
<?php
// Init array to hold exploded values
$exploded = [];
$str = '1000,10.00,10000.00@500,5.00,2500.0';
$ex = explode('@',$str);
// Iterate over the $ex-exploded items
foreach ( $ex as $exItem ) {
// Add items to the $exploded array
array_push($exploded, explode(',', $exItem));
}
print_r($exploded);
将输出
Array
(
[0] => Array
(
[0] => 1000
[1] => 10.00
[2] => 10000.00
)
[1] => Array
(
[0] => 500
[1] => 5.00
[2] => 2500.0
)
)
编辑: 如果您希望所有值都在一个数组中,则可以
$exploded = array_merge($exploded[0], $exploded[1]);
print_r($exploded);
将输出
Array
(
[0] => 1000
[1] => 10.00
[2] => 10000.00
[3] => 500
[4] => 5.00
[5] => 2500.0
)