我根据https://wordpress.org/plugins/custom-list-table-example/
的示例使用了我正在使用的功能这样设置一个这样的数组......
var $example_data = array(
array(
'ID' => 1,
'title' => '300',
'rating' => 'R',
'director' => 'Zach Snyder'
),
array(
'ID' => 7,
'title' => 'Watchmen',
'rating' => 'R',
'director' => 'Zach Snyder'
)
);
我试图用我自己的函数替换它,创建一个像这样的数组......
function create_array()
{
$count1 = $wpdb->get_results("select count(*) as totalvaluecount, value as thevalue, DATE(date_created) as thedate
FROM wp_rg_lead INNER JOIN wp_rg_lead_detail ON wp_rg_lead.id = wp_rg_lead_detail.lead_id
WHERE wp_rg_lead.form_id = '47' AND date_created BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY)
AND NOW() AND field_number = '18' GROUP BY thevalue, thedate");
$values = array();
foreach ($count1 as $page) {
$values = array_merge($values, array(array( 'rep' => $page->thevalue, $page->thedate => $page->totalvaluecount,
)));
}
function in_array_r($needle, $haystack, $strict = false)
{
foreach ($haystack as $item)
{
if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict)))
{
return true;
}
}
return false;
}
$codes = Array();
$counter = -1;
foreach($values as $key => $value)
{
if(!in_array_r($values[$key]["rep"], $codes, true))
{
$codes[++$counter] = Array();
foreach($values[$key] as $subkey => $subvalue)
{
$codes[$counter][$subkey] = $subvalue;
}
}
else
{
foreach($values[$key] as $subkey => $subvalue)
{
if($subkey != "rep" && $subkey != "id")
{
$codes[$counter][$subkey] = $subvalue;
}
}
}
}
}
如何修改我的函数以与原始函数相同的方式传递数组?