0

Dear all,
I need your help :)

i have array like this-->
$myarray([0]=>a,1
[1]=>b,2
[2]=>a,2
)

i want to split each of the array element, i want to retrieve the part a and b of each array elemet and (maybe) store it in different array like this:
$myarray1([0]=>a
[1]=>b
)
Is that possible to do?

Thank you :D

3
Contributors
3
Replies
6
Views
6 Years
Discussion Span
Last Post by atfOnly
0

Try this..

<?php 
$myarray=array(0=>"a,1",1=>"b,2",2=>"a,2");
$a=implode(",",$myarray);

$a=explode(",",$a);
$b=array();
$k=0;
for($i=0;$i<sizeof($a);$i++)
{
if($i%2==0)
{

  $b[$k]=$a[$i];
  $k++;
}
}
$c=array_unique ( $b);
print_r($c);

?>
0

Try

$myarray=array("a,cake", "b,cheese", "c,pacman");
$anotherArray=array();
foreach ($myarray as $value) {
 $values=explode(",", $value); 
 foreach ($values as $item) { 
  $anotherArray[]=$item; 
 } 
}

:D

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.