Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array 1

Status
Not open for further replies.

xbl12

Programmer
Dec 12, 2006
66
Hi;
I got two arrays which is first_array and second_array,
i want to keep the elements which in second_array and the first latter do not start with a,k,c,m,d,e,f,g.
so i just want to keep 'pppa','yyyyk','zzjjj' for the second_array,could anyone tell me how do that, please, thanks


$first_Array=('a','k','b','c','m','d','e','f','g')

$second_Array=('ahhh','kggg','bhjj','ctert','msd','dgx','efd','fffd','gdf','pppa','yyyyk','zzjjj')
 
Hi

Code:
$first=array('a','k','b','c','m','d','e','f','g');
$second=array('ahhh','kggg','bhjj','ctert','msd','dgx','efd','fffd','gdf','pppa'
,'yyyyk','zzjjj');
$third=array_filter($second,'hmm');

function hmm($one)
{
  global $first;
  return ! in_array(substr($one,0,1),$first);
}

Feherke.
 
thnaks, but it does not work for non english letter
like the following;
$first=array('?','?','?','?','?');
$second=array('?','?','?','?','?','??','??','??','??','??');
 
but you didn't ask that. it's unreasonable to expect someone to help you when you have not given them the full facts.

php5 unicode support is not great. but i suspect this variation on Feherke's script should work

Code:
mb_internal_encoding("UTF-8");
$first=array('?','?','?','?','?');
$second=array('?','?','?','?','?','??','??','??','??','??'); 
$third=array_filter($second,'hmm');

function hmm($one) {
  global $first;
  return ! in_array(mb_substr($one,0,1),$first);
}
 
Thanks a lot, and sorry about that, i thought it does not make any different.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top