Reputation: 11
I had a array of list like this :
A = (a.11, b.12, c.dd)
I want to store the above array values in two different arrays like
B = (a, b, c)
C = (11,12,dd)
Upvotes: 1
Views: 4777
Reputation: 92
Hope this will help you:
$a = array("a.11,b.12,c.dd");
$b = array();
$d = array();
foreach ($a as $val)
{
$c =explode(',', $val);
foreach ($c as $v)
{
$e =explode('.', $v);
array_push($b,$e[0]);
array_push($d,$e[1]);
}
}
print_r($b);
print_r($d);
Working demo
Upvotes: 1
Reputation: 28564
Try this,
$C = [];
$B = array_map(function($v) use(&$C){$arr = explode('.', $v); $C[] = $v[1]; return $v[0];}, $A);
Upvotes: 0
Reputation: 2126
foreach($A as $v) {
$v = explode('.', $v);
$B[] = $v[0];
$C[] = $v[1]
}
Upvotes: 0