954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Split Value in each Array Element ??

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

atfOnly
Newbie Poster
20 posts since May 2010
Reputation Points: 10
Solved Threads: 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);

?>
divyakrishnan
Posting Whiz in Training
201 posts since May 2010
Reputation Points: 30
Solved Threads: 24
 

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

GigsD4X
Light Poster
31 posts since May 2010
Reputation Points: 10
Solved Threads: 2
 

Thank you very much..works perfectly :)

atfOnly
Newbie Poster
20 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: