AV1611 Posted December 27, 2006 Share Posted December 27, 2006 I'm in over my head :-\okyou guys helped me with this command... first:if (in_array($str, $array)) { // do it}but I want $str to be an arrayso what I want to do is see if each array item is a member of another array... Link to comment https://forums.phpfreaks.com/topic/31983-solved-search-array-in-an-array/ Share on other sites More sharing options...
AV1611 Posted December 27, 2006 Author Share Posted December 27, 2006 OKI think I'm on the right track, but I have one more question:[code]$s=0$str=array();while($s<=26) {$str[]="player_".$s;}foreach ($str AS $item) { if (in_array($item, $data)) { // I want to echo the current array item from $data } }[/code] Link to comment https://forums.phpfreaks.com/topic/31983-solved-search-array-in-an-array/#findComment-148434 Share on other sites More sharing options...
Barand Posted December 27, 2006 Share Posted December 27, 2006 If it is in the array then the matching item in $data will be the same as $item ??? Link to comment https://forums.phpfreaks.com/topic/31983-solved-search-array-in-an-array/#findComment-148456 Share on other sites More sharing options...
Barand Posted December 27, 2006 Share Posted December 27, 2006 PS Having created the $str array you can find which are in the $data array with http://www.php.net/array_intersect[code]<?php$str = array ('a', 'b', 'c', 'd', 'e');$data = array ('a', 'd', 'g');$result = array_intersect($data, $str);echo '<pre>', print_r($result, true), '</pre>';?>[/code]-->[pre][nobbc]Array( [0] => a [1] => d)[/nobbc][/pre] Link to comment https://forums.phpfreaks.com/topic/31983-solved-search-array-in-an-array/#findComment-148464 Share on other sites More sharing options...
AV1611 Posted December 28, 2006 Author Share Posted December 28, 2006 Thats a HUGE help Barand... ;D Link to comment https://forums.phpfreaks.com/topic/31983-solved-search-array-in-an-array/#findComment-148627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.