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

Recommended Answers

All 3 Replies

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);

?>

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

Thank you very much..works perfectly :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.