PHP中类似于in_数组的C函数
C语言中是否有类似于PHP中数组中的PHP中类似于in_数组的C函数,php,c,Php,C,C语言中是否有类似于PHP中数组中的的函数 不,但您可以这样实现 <?php $os = array("Mac", "NT", "Irix", "Linux"); if (in_array("Irix", $os)) { echo "Got Irix"; } if (in_array("mac", $os)) { echo "Got mac"; } ?> typedef int(*cmpfunc)(void*,void*); 数组中的int(void*array
的函数 不,但您可以这样实现
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
typedef int(*cmpfunc)(void*,void*);
数组中的int(void*array[],int size,void*lookfor,cmpfunc-cmp)
{
int i;
对于(i=0;i
不,您必须自己实现:)顺便说一句,in_array()
是区分大小写的,因此in_array('mac',$s)
将是false
。
typedef int (*cmpfunc)(void *, void *);
int in_array(void *array[], int size, void *lookfor, cmpfunc cmp)
{
int i;
for (i = 0; i < size; i++)
if (cmp(lookfor, array[i]) == 0)
return 1;
return 0;
}
int main()
{
char *str[] = {"this is test", "a", "b", "c", "d"};
if (in_array(str, 5, "c", strcmp))
printf("yes\n");
else
printf("no\n");
return 0;
}