php二维数组查找

2018-06-25  本文已影响0人  kkgokk

function find(target,array){
row = count(array);
col = count(array[0]);
for(i = 0,j = col-1;true;){ if(array[i][j] == target){ return 1; }else if(array[i][j] > target &&j > 0){
j--; }else if(array[i][j] < target &&i < row-1){i++;
}else if( i ==row-1 && array[i][j] <target ){
return 0;
}else if(j == 0 &&array[i][j] > $target){
return 0;
}
}
}

字符串空格替换

function replaceSpace(str) { // write code herestr_array = str_split(str);rstr = '';
foreach(str_array ass){
if(s == ' '){rstr .= '%20';
}else{
rstr .=s;
}
}
return $rstr;
}

上一篇下一篇

猜你喜欢

热点阅读