【发布时间】:2014-01-11 06:25:20
【问题描述】:
我有两个名为 $data 和 $new_el 的数组,以及两个数组的两个 foreach 循环。下面是我的代码。
我想比较两个数组的 0 索引变量,因为两个数组都有相同的名称变量,它的 0 索引。我为 $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 或数组几乎没有关系。您只是要求我们调试一段混淆代码。我非常怀疑这个答案会对除你之外的任何人有所帮助,所以我会传递这个答案。