我有一个数组值
$array[0]="Test|121";
$array[1]="Test|goo";
$array[2]="Test|example";
我需要将其更改为
$array[0]="Test";
$array[1]="121";
$array[2]="goo";
$array[3]="example";
谁能告诉我我该怎么做。
我有一个数组值
$array[0]="Test|121";
$array[1]="Test|goo";
$array[2]="Test|example";
我需要将其更改为
$array[0]="Test";
$array[1]="121";
$array[2]="goo";
$array[3]="example";
谁能告诉我我该怎么做。
$array[0]="Test|121";
$array[1]="Test|goo";
$array[2]="Test|example";
$result = explode( '|', array_shift( $array));
foreach( $array as $k => $v) {
    $parts = explode( '|', $v);
    $result[] = array_pop( $parts);
}
var_dump( $result);
这会产生复杂且非常奇怪的 输出:
array(4) {
  [0]=>
  string(4) "Test"
  [1]=>
  string(3) "121"
  [2]=>
  string(3) "goo"
  [3]=>
  string(7) "example"
}
function cutStr(&$elem, $key)
{
    $ret = explode('|', $elem);
    if ( $key == 0 )
        $elem = $ret[0];
    else
        $elem = $ret[1];
}
$array[0]="Test|121";
$array[1]="Test|goo";
$array[2]="Test|example";
array_walk($array, 'cutStr');
print_r($array);
尝试这个。