banner rotator advertising with probability - php

I have banners advertising with number of views, like CPM system.
And for example :
i have 3 banner:
banner1 with 20.000 nr of views
banner2 with 10.000 nr of views
banner3 with 5.000 nr of views
and on my website the banner must to appear in this position (when the page is reloaded) :
banner1 banner2 banner1 banner2 banner3
if the number of views is higher then the probability of apparition is higher
how can i do this in php?

First of all, your system is just... stupid. It perpetuates banners with lots of views while newly created banners with 0 or few views will never get a chance to be picked and thus will never be actually seen...
That being said, if you have an array that looks like this:
$banners = array
(
'banner1' => 1,
'banner2' => 2,
'banner3' => 4,
'banner4' => 8,
'banner5' => 16,
);
You can use a function like this one to weightily pick one banner:
function Probability($data)
{
if (is_array($data) === true) {
$result = 0;
$probability = mt_rand(1, array_sum($data));
foreach ($data as $key => $value) {
$result += $value;
if ($result >= $probability) {
return $key;
}
}
}
return false;
}
Usage (test it # CodePad.org or # IDEOne):
echo Probability($banners); // banner5
Sample from 100 executions:
Array
(
[banner5] => 41
[banner4] => 38
[banner3] => 10
[banner2] => 8
[banner1] => 3
)

Here's a php way to do it
I'm imagining your array will look something like this...
$banners = array(
array (
'name' => 'banner1',
'views' => 20
),
array (
'name' => 'banner2',
'views' => 10
),
array (
'name' => 'banner3',
'views' => 5
)
);
This function basically loops through the banners and however many views a banner has, that many items of its array index are added to an array. Then a random one is chosen. Items with more views have a better chance of being chosen.
function getWeightedRandom( $array ) {
$universe_array = array();
foreach ( $array as $k => $b ) {
$universe += $b['views'];
$universe_array = array_pad( $universe_array, $universe, $k );
}
$rand = mt_rand( 0, count( $universe_array ) -1 );
return $array[ $universe_array[ $rand ] ];
}
$r = getWeightedRandom($banners);
print_r($r);
A simple mysql option is:
select * from banners order by rand() * views desc limit 1
banners with more views will have a higher chance of being the top result

Related

How can I manipulate my array, so if there is a scan within 60min with the same

This is really hard to explain, but i will do my best.
I have a array called arrayoftransationcs which contains 4 strings. *SCAN, MEMBER_ID, RESTAURANT, TIME, PAID. If a scan is paid, it will defined as 1, and if not it will have 0.
So the main question to my problem is, how can I get scan that contain paid = 0 which has not have paid = 1 within 60 min. I will give an example.
Example A In this example, there is 3 scan which comes from the same cafe x within 20 min. The first 2 has been defined as paid = 0, and the last has been defined as paid = 1. Because there is paid = 1 within 60min with the same member_id and restaurant, i dont want any of the scan
Scan A 1635752 Cafe X 17-11-2013 21:00 Paid 1
Scan B 1635752 Cafe X 17-11-2013 20:50 Paid 0
Scan C 1635752 Cafe X 17-11-2013 20:40 Paid 0
Example B In this example, there is also 3 scan from the same member, same restaurant, within 60min, but all of them has been defined as paid = 0. Because there is no paid = 1 in this example, i want these in a array. This is the goal. But there is a twist here, because there is more than 1 scan to use, i only want the latest scan in this example, which will mean only scan A can be used
Scan A 1635752 Cafe X 17-11-2013 21:00 Paid 0
Scan B 1635752 Cafe X 17-11-2013 20:50 Paid 0
Scan C 1635752 Cafe X 17-11-2013 20:40 Paid 0
So I hope you understand the my question. I need paid = 0 scan if there is not a paid = 1 scan subsequently with the same member_id, restaurant within 60min
This is how i tried.
I am looping my array 2 times, and then checking for it the same member_id (cardid) and restaurants are equals together, if yes, then check time. If it is whitin 60min, mark the scan as double
foreach($arrayoftransationcs as $key => $array)
{
$time=$arrayoftransationcs[$key]['created'];
$cardid = $arrayoftransationcs[$key]['cardid'];
$restaurant_id = $arrayoftransationcs[$key]['restaurant_id'];
if(isset($arrayoftransationcs[$key]))
{
foreach($arrayoftransationcs as $k1=>$v1)
{
$time2=$arrayoftransationcs[$k1]['created'];
if($key<$k1)
{
if($arrayoftransationcs[$k1]['cardid']==$cardid && $arrayoftransationcs[$k1]['restaurant_id']==$restaurant_id)
{
if(compare($time,$time2))
{
$arrayoftransationcs[$key]['error'] = 'double';
$arrayoftransationcs[$k1]['error'] = 'double';
}
}
}
}
}
}
checking the time here.
function compare($firsttime, $secondtime)
{
$interval = $firsttime-$secondtime;
$dif=round(abs($interval) / 60);
if ($dif < 60 || $dif < -60 )
{
if ($dif!==0)
{
return true;
}
else
{
return false;
}
}
}
This is the place, where i filter after paid = 0 and does not contain anything in the error field.
foreach ($arrayoftransationcs as $key)
{
if($key['paid'] == 0 && empty($key['error']))
{
$ids[] = $key['transactionid'];
}
}
But I am not sure it is the right approach, I did it with the code. For technically, I select all scan which has the same membership number, restaurant with "double" in the field error, if it is paid = 1 or 0, does not matter .. this is not right, i think.
So I'm missing something here, checking if there is paid = 0 scan here if yes, check if there is a paid = 1 scan within the next 60min having the same medlem_id and restaurant. If so, then mark them as doubles.
This is how you do it:
<?php
// Data Source
$arrayoftransationcs = array(
array(
'transactionid' => 16148,
'cardid' => 10010234,
'created' => 1380650784,
'restaurant_id' => 32089,
'paid' => 1
),
array(
'transactionid' => 16552,
'cardid' => 10010241,
'created' => 1381522288,
'restaurant_id' => 41149,
'paid' => 1
),
array(
'transactionid' => 16936,
'cardid' => 10010440,
'created' => 1386247655,
'restaurant_id' => 47897,
'paid' => 0
),
array(
'transactionid' => 16808,
'cardid' => 10010557,
'created' => 1382361447,
'restaurant_id' => 43175,
'paid' => 0
),
array(
'transactionid' => 18932,
'cardid' => 10010440,
'created' => 1386247655,
'restaurant_id' => 47897,
'paid' => 1
)
);
// Helper Function
function getUnpaidWithinHour($transactions) {
$unpaid_transactions = array();
$time_now = time();
foreach ($transactions as $transaction) {
if ($transaction['paid']) continue;
if (($time_now - $transaction['created']) < 3600 && !$transaction['paid']) {
$unpaid_transactions[] = $transaction;
}
}
return $unpaid_transactions;
}
// Test
$unpaid_transactions = getUnpaidWithinHour($arrayoftransationcs);
echo "<pre>";
print_r($unpaid_transactions);
echo "<pre>";
?>
Outputs:
Array
(
[0] => Array
(
[transactionid] => 16936
[cardid] => 10010440
[created] => 1386247655
[restaurant_id] => 47897
[paid] => 0
)
)
To test if this is working, I edited the transaction 16936 to have a timestamp of 5 minutes ago and ran the function. The code correctly detected that transaction.
Try it yourself and with your own datasource.
Let's make things simple, your question is: Find paid = 0 scan if there is not paid = 1 with same member_id within 60min, since lack of test data, so i'll describe below with nature language in php style:
make an empty arrayPaid
foreach (all data) {
if time passed greater than 60min, continue;
if paid
add member_id in arrayPaid: arrayPaid[member_id] = something
continue;
if unpaid and arrayPaid[member_id] is not set
this is the data you want
}
The logic is clear, easy to write your real code. And one important thing is, your data need to be order by time in desc.
I found the answer by doing this.
foreach ($results->result_array() as $filterofresults)
{
if($filterofresults['paid'] == 1)
{
$arrayoftransationcs1[]=$filterofresults;
}
if($filterofresults['paid'] == 0)
{
$arrayoftransationcs[]=$filterofresults;
}
}
foreach($arrayoftransationcs as $key => $array)
{
$time=$arrayoftransationcs[$key]['created'];
$cardid = $arrayoftransationcs[$key]['cardid'];
$restaurant_id = $arrayoftransationcs[$key]['restaurant_id'];
if(isset($arrayoftransationcs[$key]))
{
foreach($arrayoftransationcs1 as $k1=>$v1)
{
$time2=$arrayoftransationcs1[$k1]['created'];
if($key<$k1)
{
if($arrayoftransationcs1[$k1]['cardid']==$cardid && $arrayoftransationcs1[$k1]['restaurant_id']==$restaurant_id)
{
if(compare($time,$time2))
{
$arrayoftransationcs[$key]['error'] = 'Dobbelt';
$arrayoftransationcs1[$k1]['error'] = 'Dobbelt';
}
}
}
}
}
}
foreach ($arrayoftransationcs as $key)
{
if($key['paid'] == 0 && empty($key['error']))
{
$samlet[] = get_all_data($key['transactionid']);
}
}

Recursive table which child parent relationship

I have a problem with a recursive function that takes too many resources to display a child-parent relation in a dropdown list. For example:
home
-menu 1
-menu 2
home 1
-menu 3
-menu 4
I've written some code for a recursive call to the database each time, so that's the reason why my code takes so many resources to run.
Below is my code:
--call recursive
$tmp = $this->get_nav_by_parent(0);
$a_sel = array('' => '-Select-');
$a_sel_cat = array('home' => 'home');
$this->get_child_nav_cat($tmp, 0, $a_sel);
--
public function get_nav_by_parent($parent) {
$all_nav = $this->db
->select('id, title, parent')
->where('parent',$parent)
->order_by('position')
->get('navigation_links')
->result_array();
$a_tmp = array();
foreach($all_nav as $item)
{
if($parent != 0){
$item['title'] = '--' . $item['title'];
}
$a_tmp[] = $item;
}
return $a_tmp;
}
-- Recursive function
public function get_child_nav_cat($a_data, $parent, &$a_sel) {
foreach($a_data as $item) {
$a_sel[$item['page_slug_key']] = $item['title'];
$atmp = $this->get_nav_by_parent($item['id']);
$this->get_child_nav_cat($atmp, $item['id'], $a_sel);
}
return $a_sel;
}
Please give me suggestions for the best solution to display the data as child-parent relationship in select box.
Thanks in advance!
Best way to display parent child relationship is mentain parent and child flag in Database instead of
fetching value using loop.
In your case Home, Home 1 is parent flag and menus belong on child flag.
fetch data from db and your loop look like this:-
$arr = array(0 => array('name' => 'home','parent' => 0),
1 => array('name' => 'menu 1 ','parent' => 1),
2 => array('name' => 'menu 2 ','parent' => 1),
3 => array('name' => 'home 1','parent' => 0),
4 => array('name' => 'menu 3 ','parent' => 2),
5 => array('name' => 'menu 4','parent' => 2)
);
$dd_html = '<select>';
foreach($arr as $k => $v){
if($v['parent'] == 0 )
$dd_html .='<option>'.$v['name'].'</option>';
else
$dd_html .='<option>--'.$v['name'].'</option>';
}
$dd_html .= '</select>';
echo $dd_html;
Output :-
home
-menu 1
-menu 2
home 1
-menu 3
-menu 4
Set ParentID=0 for detecting root item
then execute this:
SELECT * FROM table ORDER BY ParentID, ID
Then iterate through result and when ParentID changed, create new level.

adding elements at identical keys in multiple multidimensional arrays

I'm trying to do a web application with php and MySQL that can graph the estimate effort of a person based on the data stored in the data base
$luna_start = date('n', strtotime($row_task['data_i']));
$luna_end = date('n', strtotime($row_task['data_s']));
$luna_curenta=$luna_start;
$ultimazi_luna_curenta= cal_days_in_month(CAL_GREGORIAN, $luna_curenta,"2012");
while ($luna_curenta<=$luna_end){
//construieste vectorul
for ($i = 1; $i <= $ultimazi_luna_curenta; $i++) {
$data_curenta= date("Y-m-d", mktime(0, 0, 0, $luna_curenta, $i, 2012));
if (($data_curenta>=$row_task['data_i'])&&($data_curenta<=$row_task['data_s'])){
$efort_a['a'.$row_task['task_id']][$data_curenta]=$efort_mediu;
}
}
$luna_curenta++;
}
all that trouble for getting an array so that i can graph. the array $efort_a looks like this:
Array(
[a19] => Array(
[2012-09-20] => 2.84
[2012-09-21] => 2.84
.......
[2012-10-21] => 2.84
[2012-10-22] => 2.84
)
[a22] => Array
(
[2012-10-01] => 0.1
[2012-10-02] => 0.1
.....
[2012-11-05] => 0.1
[2012-11-06] => 0.1
[2012-11-07] => 0.1
......
[2012-11-25] => 0.1
......
[2012-11-30] => 0.1
)
[a16] => Array
(
[2012-10-08] => 4
[2012-10-09] => 4
[2012-10-10] => 4
[2012-10-11] => 4
......
[2012-10-18] => 4
[2012-10-19] => 4
)
)
further more I'm doing a little more array processing.
extract($efort_a);
$graf_data= array_add($a19,$a22,$a16);
$data = new GoogleChartData($graf_data);
$chart->addData($data);
the problem with all this code is that it isn't a dynamic one. the arrays a19, a22, a16 are named statically and in this particular case the user had only 3 tasks (task id 19, 22 and 16) ... but what if the user has multiple tasks ?.
so the questions is can this code be reorganized, maybe as a function i don't know how, to be a dynamic one ?
could it be possible to do a function that graph's all the users effort (one graph, multiple lines- one for each user)
ps: the function to do the adding of arrays based on keys is:
function array_add($a1, $a2) {
// adds the values at identical keys together
$aRes = $a1;
foreach (array_slice(func_get_args(), 1) as $aRay) {
foreach (array_intersect_key($aRay, $aRes) as $key => $val) $aRes[$key] += $val;
$aRes += $aRay;
}
return $aRes;
}
========================================= day 2 =======================
after some thinking i thought to give another try... so in order to name the keys of array effort_a dynamically i need to know where to stop with the incrementation so :
$sql_nrtask='SELECT *, COUNT(user) AS nr_task
FROM task
WHERE user="ASD"
ORDER BY data_i ASC
';
$query_nrtask= mysql_query($sql_nrtask) or die ('rrr');
while ($row_nrtask= mysql_fetch_array($query_nrtask)) {
$nr_task=$row_nrtask['nr_task']; // no we know how many sub-arrays we'll have
}
for ($j++;$j<=$nr_task;$j++){
while ($luna_curenta<=$luna_end){
//construieste vectorul
for ($i = 1; $i <= $ultimazi_luna_curenta; $i++) {
$data_curenta= date("Y-m-d", mktime(0, 0, 0, $luna_curenta, $i, 2012));
if (($data_curenta>=$row_task['data_i'])&&($data_curenta<=$row_task['data_s'])){
$efort_a['$a'.$j][$data_curenta]=$efort_mediu;
}
}
$luna_curenta++;
}
}
the problem is know that i don't know hot to merge the arrays within $efort_a with 2 conditions:
keeping indexes where they are the same and adding values
adding a new index where it is a new element

PHP/mySQL: Import data and store in hierarchical nested set for use with jsTree

I'm using jsTree to view hierarchical data that is stored in a mySQL database as a nested set (left, right, level, etc.). This is working fine, but I need to allow users to import data by uploading a CSV file. When they do so, any existing data in the table will be removed so I don't have to worry about updating the left/right fields.
The data they will be uploading will be in this format:
"Code","Title"
"100","Unit 100"
"200","Unit 200"
"101","Task 101: This is a task"
"102","Task 102: Another task"
"201","Task 201: Yet another"
"300","Unit 300"
"301","Task 301: Another one"
Everything will be a child of a main "Group" that is a level 1 node. All of the "codes" divisible by 100 (ie. 100, 200, 300) will be level 2 (parent nodes.. children of "Group"). All others will be level 3 (child) nodes of their respective parent nodes (ie. 101 and 102 are children of 100, 201 is a child of 200, etc.)
The resulting table in mySQL should look like this:
id parent_id position left right level title
1 0 0 1 18 0 ROOT
2 1 0 2 17 1 Group
3 2 0 3 8 2 Unit 100
4 2 1 9 12 2 Unit 200
5 3 0 4 5 3 Task 101: This is a task
6 3 1 6 7 3 Task 102: Another task
7 4 0 10 11 3 Task 201: Yet another
8 2 2 13 16 2 Unit 300
9 8 0 14 15 3 Task 301: Another one
The tree would then look like this:
My question is: using PHP, what is the best method to accomplish this? I already have code in place that pulls the data contained in the uploaded CSV file and stores it in an array, but I'm not sure what the logic to convert this to a nested set should look like.
Right now, the data is stored in a 2-dimensional array called $data (in the format $data[$col][$row]):
$data[0][0] = "Code";
$data[0][1] = "100";
$data[0][2] = "200";
$data[0][3] = "101";
$data[0][4] = "102";
$data[0][5] = "201";
$data[0][6] = "300";
$data[0][7] = "301";
$data[1][0] = "Title";
$data[1][1] = "Unit 100";
$data[1][2] = "Unit 200";
$data[1][3] = "Task 101: This is a task";
$data[1][4] = "Task 102: Another task";
$data[1][5] = "Task 201: Yet another";
$data[1][6] = "Unit 300";
$data[1][7] = "Task 301: Another one";
Array ( [0] => Array ( [0] => Code [1] => 100 [2] => 200 [3] => 101 [4] => 102 [5] => 201 [6] => 300 [7] => 301 ) [1] => Array ( [0] => Title [1] => Unit 100 [2] => Unit 200 [3] => Task 101: This is a task [4] => Task 102: Another task [5] => Task 201: Yet another [6] => Unit 300 [7] => Task 301: Another one ) )
Any help would be very much appreciated. I now have the parent_id, position, and level being calculated correctly... I just need to figure out the left/right part. Here is the code I'm currently using (thanks for getting me started Matteo):
$rows = array();
// insert ROOT row
$rows[] = array(
'id' => 1,
'parent_id' => 0,
'position' => 0,
'left' => 1,
'right' => 10000, // just a guess, will need updated later
'level' => 0,
'title' => 'ROOT',
);
echo "<br>";
print_r($rows[0]);
// insert group row
$rows[] = array(
'id' => 2,
'parent_id' => 1,
'position' => 0,
'left' => 2,
'right' => 9999, // just a guess, will need updated later
'level' => 1,
'title' => 'Group',
);
echo "<br>";
print_r($rows[1]);
// next ID to be used
$id = 3;
// keep track of code => ID correspondence
$map = array();
// parse data
for ($i = 1, $c = count($data[0]); $i < $c; ++$i) {
// save ID in the map
$map[$data[0][$i]] = $id;
// initialize the current row
$row = array(
'id' => $id,
'parent_id' => 1,
'position' => 0,
'left' => 0,
'right' => 0,
'level' => 1,
'title' => $data[1][$i],
);
// if the code is multiple of 100
if ($data[0][$i] % 100 == 0) {
$row['parent_id'] = 2;
$row['level'] = 2;
$row['position'] = (floor($data[0][$i] / 100)) - 1;
} else {
// get parent id from map
$row['parent_id'] = $map[floor($data[0][$i] / 100) * 100];
$row['level'] = 3;
$row['position'] = $data[0][$i] % 100;
}
// add the row
$rows[] = $row;
++$id;
echo "<br>";
print_r($row);
}
Given your $data array, you could parse it like this:
// this will contain all the rows to be inserted in your DB
$rows = array();
// insert ROOT row
$rows[0] = array(
'id' => 1,
'parent_id' => 0,
'position' => 0,
'level' => 0,
'left' => 1,
'right' => 10000,
'title' => 'ROOT',
);
// insert group row
$rows[1] = array(
'id' => 2,
'parent_id' => 1,
'position' => 0,
'level' => 1,
'left' => 2,
'right' => 9999,
'title' => 'Group',
);
// keep trace of code => ID correspondence
$map = array();
// next ID to be used
$id = 3;
// keep father => sons relationship
$tree = array();
// keep trace of code => row index correspondence
$indexes = array();
// next row index
$index = 2;
// parse your data
for ($i = 1, $c = count($data[0]); $i < $c; ++$i) {
// current code
$code = $data[0][$i];
// save ID in the map
$map[$code] = $id;
// update the indexes map
$indexes[$code] = $index;
// prepare the current row
$row = array(
'id' => $id,
'title' => $data[1][$i],
)
// get the value of code mod 100
$mod = $code % 100;
// if the code is multiple of 100
if ($mod == 0) {
// the parent_id is 2
$row['parent_id'] = 2;
// it is level two
$row['level'] = 2;
// compute position
$row['position'] = floor($code / 100) - 1;
}
else {
// get the parent code
$parent = floor($code / 100) * 100;
// get parent id from map using parent code
$row['parent_id'] = $map[$parent];
// it is level three
$row['level'] = 3;
// save position
$row['position'] = $mod;
// save in relationship tree
$tree[$parent][] = $code;
}
// add the row
$rows[$index] = $row;
// prepare next id
++$id;
// update row index
++$index;
}
// sort the relationship tree base on the parent code (key)
ksort($tree, SORT_NUMERIC);
// next left value
$left = 3;
// now, using the relationship tree, assign left and right
foreach ($tree as $parent => $sons) {
// calculate parent left value
$parentLeft = $left;
// prepare next left value
++$left;
// to be sure that the sons are in order
sort($sons, SORT_NUMERIC);
// assign values to sons
foreach ($sons as $son) {
// index in the rows array
$index = $indexes[$son];
// set left value
$rows[$index]['left'] = $left;
// set right value
$rows[$index]['right'] = $left + 1;
// increment left value
$left += 2;
}
// calculate parent right value
$parentRight = $left;
// prepare next left value
++$left;
// index of parent in the rows array
$index = $indexes[$parent];
// set the values
$rows[$index]['left'] = $parentLeft;
$rows[$index]['right'] = $parentRight;
}
// update group row right value
$rows[1]['right'] = $left;
// prepare next left value
++$left;
// update root row right value
$rows[0]['right'] = $left;
At this point, you can insert all the rows one at a time.
EDIT: now the script should handle all the required values correctly.
I would use Doctrine2 with a Nested Set Extension. You could use a nice and convenient API and don't have to worry about the nested set implementation:
See
http://www.gediminasm.org/article/tree-nestedset-behavior-extension-for-doctrine-2
or http://wildlyinaccurate.com/simple-nested-sets-in-doctrine-2
There are several extensions on github. Actually, i don't know which one is best.
https://github.com/l3pp4rd/DoctrineExtensions
https://github.com/guilhermeblanco/Doctrine2-Hierarchical-Structural-Behavior
https://github.com/blt04/doctrine2-nestedset
List item
If your data is flat, you could parse for keywords like 'Unit' or 'Task' to arrange your elements to the needed hierarchical order.

Using supplier with largest margin using PHP logic

I have the following values from a database call that I want to apply some logic to. I thought I could originally use PHP's max however this doesn't appear to be the case.
I have three suppliers of a product. They might not all stock the item I am displaying, and they all offer a different margin, on a product by product basis though, so that is why I can't just say generally supplier 1 is better than supplier 2 etc.
$supplier1Live = 1
$supplier2Live = 1
$supplier3Live = 0
$marginSupplier1 = 20
$marginSupplier2 = 40
$martinSupplier3 = 50
In this example I would want to use Supplier 2 as they stock the product supplier2Live = 1 and also have the better margin than the other supplier who stocks the product (supplier1)
My mind however is drawing a complete blank in how to code this?
I thought I could add it to an array giving:
$array = array(
"supplier1" => array(
"live" => 1,
"margin" => 20
),
"supplier2" => array(
"live" => 1,
"margin" => 40
),
"supplier3" => array(
"live" => 0,
"margin" => 50
)
);
And run something on that, but not sure what to.
Filter the array using array_filter (filter by live==1), and then find the maximum out of the resultant array (maximum on the "margin" value)
Like this, if I understand correctly
$array = array(
"supplier1" => array(
"live" => 1,
"margin" => 20
),
"supplier2" => array(
"live" => 1,
"margin" => 40
),
"supplier3" => array(
"live" => 0,
"margin" => 50
)
);
$res = array_filter($array,function($v){return $v["live"];});
$supplier = array_reduce($res, function($a, $b){
return $a["margin"]>$b["margin"]?$a:$b;
});
print_r($supplier);
Try something like this:
$best_supplier = null;
$best_supplier_margin = null;
foreach($array as $name => $supplier) {
if($supplier['live']) {
if($supplier['margin'] > $best_supplier_margin || is_null($best_supplier_margin)) {
$best_supplier = $name;
$best_supplier_margin = $supplier['margin'];
}
}
}
if(is_null($best_supplier)) throw new Exception('No suppliers are live!');
echo $best_supplier;
So you basically want to find the max of supplierXLive * marginSupplierX?
You can also implement a custom compare function and provide it to PHPs usort() function

Categories