我有两个数组,分别命名为$data
和$new_el
,两个数组为foreach
。以下是我的代码。比较两个数组并找到匹配值并打印
我想比较两个数组的0索引变量,因为两个数组具有相同的名称变量它的0 index.i给$ data数组中的变量值一些条件如果$ data数组0索引变量是0,那么它存储“CJ”,如果可变长度是1,2或3,那么它分配01,02,03等,如果变量值是11,12,则表示两位数存储与来自服务器的相同。并且比较两个数组和如果两个数组0的索引值匹配,则打印所有的1,2,3等索引值。
我试了很多,但我找不到任何解决方案。请尽快提供帮助。
function curlUsingGet($url, $data)
{
if(empty($url) OR empty($data))
{
return 'Error: invalid Url or Data';
}
$fields_string = '';
foreach ($data as $key => $value) {
$fields_string .= $key . '=' . urlencode($value) . '&';
}
rtrim($fields_string,'&');
$urlStringData = $url.'?'.$fields_string;
$_SESSION['urlStringData'] = $urlStringData;
$cookie = "cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,0);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0;
Windows NT 6.1)");
curl_setopt($ch, CURLOPT_COOKIESESSION,true);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_FRESH_CONNECT,true);
curl_setopt($ch, CURLOPT_URL,$urlStringData);
$return = curl_exec($ch);
$arrele = explode('|',$return);
foreach ($arrele as $val) {
$num = 0;
$new_el = explode('~',$val);
$crt = $new_el[0];
if ($crt == '0') {
echo $crt = "CJ";
} elseif (strlen($crt) == 1) {
echo $crt = sprintf($num,$crt);
} else {
echo $crt;
}
}
$_SESSION['court'];
$courtone = explode(',', $_SESSION['court']);
$len = count($courtone);
if ($len < 2) {
echo "Invalid data from server";
}
$courtstring = $courtone[0];
$_SESSION['courtnewdate'] = $courtone[1];
$courtnew = explode('~',$courtstring);
foreach ($courtnew as $val) {
$data = explode('@@',$val);
$data[0];
}
curl_close($ch);
}
$data = array('u' => $_SESSION['councel']);
echo curlUsingGet('http://"url":8080/causelist/CauseListData', $data);
正如我所看到的,这个问题与curl,foreach,PHP或数组无关。您只是要求我们调试一段混淆的代码。我非常怀疑答案会帮助除了你之外的任何人,所以我会通过这个。 –