I have an array something like this
$arr1 = array(
'0' => '674534856|213123213|232313123',
'1' => '349578449|782374879|232313123'
);
I loop through the arr1 array,
for ($x=0; $x < $count; $x++) {
$check = explode("|", $arr1开发者_Python百科[$x]);
array_pop($check);
$count_check = count($check);
for ($z=0; $z < $count_check; $z++) {
array_push($result, $check[$z]);
}
}
It's not working as expected. Any help appreciated. Thanks.
EDIT $result
is result array
Just implode()
everything in your input array with the same delimiter to flatten it to a single string, and then explode()
by that delimiter:
$result = explode('|', implode('|', $arr1));
Try
$result = explode('|', join('|', $arr1));
// outputs
array('674534856', '213123213', '232313123', '349578449', '782374879', '232313123')
Or
$result = array_map(function($temp) { return explode('|', $temp); }, $arr1);
// outputs
array(
[0] => array('674534856', '213123213', '232313123'),
[1] => array('349578449', '782374879', '232313123')
)
精彩评论