Hi!
Please let me know if anyone knows a solution to sort an array based on the keys e.g. $arr[key1]=array(); $arr[key2]=array();
Best Regards,
Snt
Hi!
Please let me know if anyone knows a solution to sort an array based on the keys e.g. $arr[key1]=array(); $arr[key2]=array();
Best Regards,
Snt
[man]ksort()[/man] The manual is a terrible thing to waste.
Hi!
Thanks a llot for the tip!
Let me know if there's a possibility to sort the results DESC instead of ASC.
Best Regards,
Snt
[man]krsort()[/man]
No really... the manual is really a useful tool...
The sort flags doesn't work, also, it sais in the manual that the results are not replyable.
Best Regards,
Snt
If the Sort Flags don't work, it's either 1) you are using a version of PHP prior to version 4, or 2) you aren't using them correctly.
Post your code so we can look to see why it isn't working.
$this[date][keys]="";
ksort($this);
reset($this);
return $this;
I am looking for a way to order the array on the first key.
Best Regards,
Snt
Post what your array looks like too... a sample array...
function returnClients($from,$to,$limit) { global $username, $rate, $salesrate; $this = array();
$eurofrom=$from{0}.$from{1}.$from{2}.$from{3}."-".$from{4}.$from{5}."-".$from{6}.$from{7};
$euroto=$to{0}.$to{1}.$to{2}.$to{3}."-".$to{4}.$to{5}."-".$to{6}.$to{7};
if ($from) {$andNCC=" AND `EG_DATE`>='".$from."' AND `EG_DATE`<='".$to."'"; }
if ($from) {$andEURO=" AND `date`>='".$eurofrom."' AND `date`<='".$euroto."'"; }
if ($from) {$andSMS=" AND `date`>='".$from."' AND `date`<='".$to."'"; }
if ($from) {$andC=" AND `date`>='".$from."' AND `date`<='".$to."'"; }
if ($from) {$andADMINNCC=" WHERE `EG_DATE`>='".$from."' AND `EG_DATE`<='".$to."'"; }
if ($from) {$andADMINEURO=" WHERE `date`>='".$eurofrom."' AND `date`<='".$euroto."'"; }
if ($from) {$andADMINSMS=" WHERE `date`>='".$from."' AND `date`<='".$to."'"; }
if ($from) {$andADMINC=" WHERE `date`>='".$from."' AND `date`<='".$to."'"; }
if ($limit==10) {$limit=" LIMIT ".$limit;} else {$limit="";}
//NOCREDITCARD
if ($username=="admin") {$result = mysql_query("SELECT * FROM `ncc_transactions`".$andADMINNCC." order by EG_DATE DESC$limit");}
else {$result = mysql_query("SELECT * FROM `ncc_transactions` WHERE `EG_EXTLOGIN`='".$username."'".$andNCC." order by EG_DATE DESC$limit"); }
while($row = mysql_fetch_array($result)) {
$minutes=$row[EG_MINUTES]/60;
$perminuterate=(($row[EG_RATES]/100)/100)*$rate;
$earnings=($perminuterate*$minutes);
if (!is_array($this[$row["EG_DATE"]])) { $this[$row[EG_DATE]]= array(); }
if (!is_array($this[$row["EG_DATE"]][$row["EG_ID"]])) {$this[$row[EG_DATE]][$row["EG_ID"]]= array();}
$this[$row["EG_DATE"]][$row["EG_ID"]]["date"]=$row[EG_DATE];
$this[$row["EG_DATE"]]["date"]=$row[EG_DATE];
$this[$row["EG_DATE"]][$row["EG_ID"]]["id"]=$row[EG_ID];
$this[$row["EG_DATE"]][$row["EG_ID"]]["type"]="NOCREDITCARD";
$this[$row["EG_DATE"]][$row["EG_ID"]]["user"]=$row[EG_ERPLOGIN]."[".$row[EG_EXTLOGIN]."]";
$this[$row["EG_DATE"]][$row["EG_ID"]]["minutes"]=$row[EG_MINUTES]/60;
$this[$row["EG_DATE"]][$row["EG_ID"]]["rate"]=(($row[EG_RATES]/100)/100)*$rate;
$this[$row["EG_DATE"]][$row["EG_ID"]]["revenue"]=((($row[EG_RATES]/100)*($row[EG_MINUTES]/60))/100)*$rate;
$this[$row["EG_DATE"]][$row["EG_ID"]]["country"]=$row["EG_COUNTRY"];
if ($row[error]) {$this[$row["EG_DATE"]][$row["EG_ID"]]["status"]=$row[error]; } else { $this[$row["EG_DATE"]][$row["EG_ID"]]["status"]="OK"; }
// 1 dialer, 2 phone2enter, 3 One shot billing, 4 One shot dialer france, 5 One shot Phone2enter France
switch ($row[EG_TYPETRAMEID]) {
case 1:
$this[$row["EG_DATE"]][$row["EG_ID"]]["calltype"]="dialer";
$this[$row["EG_DATE"]]["modemcalls"]=$this[$row["EG_DATE"]]["modemcalls"]+1;
break;
case 2:
$this[$row["EG_DATE"]][$row["EG_ID"]]["calltype"]="phone";
$this[$row["EG_DATE"]]["phonecalls"]=$this[$row["EG_DATE"]]["phonecalls"]+1;
break;
case 3:
$this[$row["EG_DATE"]][$row["EG_ID"]]["calltype"]="one shot";
$this[$row["EG_DATE"]]["oneshotcalls"]=$this[$row["EG_DATE"]]["oneshotcalls"]+1;
break;
case 4:
$this[$row["EG_DATE"]][$row["EG_ID"]]["calltype"]="one shot dialer France";
$this[$row["EG_DATE"]]["oneshotcalls"]=$this[$row["EG_DATE"]]["oneshotcalls"]+1;
break;
case 5:
$this[$row["EG_DATE"]][$row["EG_ID"]]["calltype"]="one shot phone France";
$this[$row["EG_DATE"]]["oneshotcalls"]=$this[$row["EG_DATE"]]["oneshotcalls"]+1;
break;
}
$this[$row["EG_DATE"]]["revenue"]=$this[$row["EG_DATE"]]["revenue"]+$earnings;
$this[$row["EG_DATE"]]["minutes"]=$this[$row["EG_DATE"]]["minutes"]+$minutes;
}
//SMS
if ($username=="admin") {$result = mysql_query("SELECT * FROM `sms_transactions`".$andADMINSMS." order by date DESC$limit");}
else {$result = mysql_query("SELECT * FROM `sms_transactions` WHERE `ref`='".$username."'".$andSMS." order by date DESC$limit");}
while($row = mysql_fetch_array($result)) {
if (!is_array($this[$row[date]])) { $this[$row[date]]= array(); }
if (!is_array($this[$row[date]]["sms".$row[sender]])) {$this[$row[date]]["sms".$row[sender]]= array();}
$this[$row[date]]["sms".$row[sender]]["date"]=$row[date];
$this[$row[date]]["date"]=$row[date];
$this[$row[date]]["sms".$row[sender]]["type"]="SMS";
$this[$row[date]]["sms".$row[sender]]["country"]=$row[country];
$this[$row[date]]["sms".$row[sender]]["sender"]=$row[sender];
$this[$row[date]]["sms".$row[sender]]["id"]=$row[id];
$this[$row[date]]["sms".$row[sender]]["code"]=$row[code];
$this[$row[date]]["sms".$row[sender]]["operator"]=$row[operator];
$this[$row[date]]["sms".$row[sender]]["status"]="OK";
$this[$row[date]]["sms".$row[sender]]["msg"]=$this[$row[date]]["sms".$row[sender]]["msg"]+1;
switch ($row[country]) {
case "nl":
switch ($row[operator]) {
case "orange":
$this[$row[date]]["sms".$row[sender]]["rate"]=(((0.52/100)*75)/100)*$rate;
$this[$row[date]]["sms".$row[sender]]["revenue"]=$this[$row[date]]["sms".$row[sender]]["revenue"]+(((0.52/100)*75)/100)*$rate;
$this[$row[date]]["smsrevenue"]=$this[$row[date]]["smsrevenue"]+(((0.52/100)*75)/100)*$rate;
break;
case "t-mobile":
$this[$row[date]]["sms".$row[sender]]["rate"]=(((0.53/100)*75)/100)*$rate;
$this[$row[date]]["sms".$row[sender]]["revenue"]=$this[$row[date]]["sms".$row[sender]]["revenue"]+(((0.53/100)*75)/100)*$rate;
$this[$row[date]]["smsrevenue"]=$this[$row[date]]["smsrevenue"]+(((0.53/100)*75)/100)*$rate;
break;
case "o2":
$this[$row[date]]["sms".$row[sender]]["rate"]=(((0.52/100)*75)/100)*$rate;
$this[$row[date]]["sms".$row[sender]]["revenue"]=$this[$row[date]]["sms".$row[sender]]["revenue"]+(((0.52/100)*75)/100)*$rate;
$this[$row[date]]["smsrevenue"]=$this[$row[date]]["smsrevenue"]+(((0.52/100)*75)/100)*$rate;
break;
case "kpn":
$this[$row[date]]["sms".$row[sender]]["rate"]=(((0.59/100)*75)/100)*$rate;
$this[$row[date]]["sms".$row[sender]]["revenue"]=$this[$row[date]]["sms".$row[sender]]["revenue"]+(((0.59/100)*75)/100)*$rate;
$this[$row[date]]["smsrevenue"]=$this[$row[date]]["smsrevenue"]+(((0.59/100)*75)/100)*$rate;
break;
case "d2 vodafone":
$this[$row[date]]["sms".$row[sender]]["rate"]=(((0.40/100)*75)/100)*$rate;
$this[$row[date]]["sms".$row[sender]]["revenue"]=$this[$row[date]]["sms".$row[sender]]["revenue"]+(((0.40/100)*75)/100)*$rate;
$this[$row[date]]["smsrevenue"]=$this[$row[date]]["smsrevenue"]+(((0.40/100)*75)/100)*$rate;
break;
}
break;
}
$this[$row[date]]["sms"]=$this[$row[date]]["sms"]+1;
$smsclients=$smsclients+1;
$this[$row[date]]["earnings"]=$this[$row[date]]["earnings"]+$clients[$row[date]]["sms".$row[sender]]["revenue"];
}
ksort($this);
reset($this);
return $this;
}
Have Fun!
Snt