I have an SQL query :
SELECT
DATE,
ID_DOMAIN,
SUM(CLICKS) AS CLICKS,
SUM(ADS) AS ADS,
SUM(CONVERSION) AS CONVERSION,
FROM website_stats
WHERE ID_USER_PRODUCT_DIFFUSER = :id_user_product_diffuser
AND DATE >= :date_begin
AND DATE <= :date_end
AND ID_DOMAIN != 0
GROUP BY DATE, ID_DOMAIN;
In my PDO fetchAll, I use $sth->fetchAll(PDO::FETCH_ASSOC | PDO::FETCH_GROUP). Then I have this output :
array(2) {
["2018-09-14"]=>
array(2) {
[0]=>
array(4) {
["ID_DOMAIN"]=>
string(1) "7"
["CLICKS"]=>
string(4) "1092"
["ADS"]=>
string(4) "1070"
["CONVERSION"]=>
string(3) "269"
}
[1]=>
array(4) {
["ID_DOMAIN"]=>
string(1) "9"
["CLICKS"]=>
string(3) "459"
["ADS"]=>
string(3) "452"
["CONVERSION"]=>
string(2) "56"
}
}
["2018-09-15"]=>
array(2) {
[0]=>
array(4) {
["ID_DOMAIN"]=>
string(1) "7"
["CLICKS"]=>
string(3) "914"
["ADS"]=>
string(3) "880"
["CONVERSION"]=>
string(3) "166"
}
[1]=>
array(4) {
["ID_DOMAIN"]=>
string(1) "9"
["CLICKS"]=>
string(3) "365"
["ADS"]=>
string(3) "361"
["CONVERSION"]=>
string(2) "57"
}
}
}
But for my code, I need the ID_DOMAIN a key in my sub array. It's possible without looping ? I means, just with PDO::FETCH* ? In fact, I need an array just like this :
array(2) {
["2018-09-14"]=>
array(3) {
[7]=>
array(3) {
["CLICKS"]=>
string(4) "1092"
["ADS"]=>
string(4) "1070"
["CONVERSION"]=>
string(3) "269"
}
[9]=>
array(3) {
["ID_DOMAIN"]=>
string(1) "9"
["CLICKS"]=>
string(3) "459"
["ADS"]=>
string(3) "452"
["CONVERSION"]=>
string(2) "56"
}
}
["2018-09-15"]=>
array(2) {
[7]=>
array(3) {
["ID_DOMAIN"]=>
string(1) "7"
["CLICKS"]=>
string(3) "914"
["ADS"]=>
string(3) "880"
["CONVERSION"]=>
string(3) "166"
}
[9]=>
array(3) {
["CLICKS"]=>
string(3) "365"
["ADS"]=>
string(3) "361"
["CONVERSION"]=>
string(2) "57"
}
}
}
I search for the good PDO fetch mode for long time but it seems like nobody has this problem in this website :/
Thank you in advance :)
Related
I want to make a dynamic valuation. So the idea is like this :
In my database I've user table contains 'score'.
And I've category table contains fields 'minScore' and 'categoryName(bad, good, awesome)'
And In the end I want to get result like this categoryName=>howMuchUserBasedOnScore.
I'm thinking like this :
function valuation(){
$allScore = $this->db->select('score')->get('user')->result();
$category = $this->db->get('categori')->result();
$arrCategori = array();
foreach ($allScore as $value) {
foreach($categori as $row){
if($value->score <= $row->minScore){
array_push($arrCategori, )
//I don't know what should I do
}
}
}
}
can anyone help me?
edit :
Now I add maxScore into my category table field.
and I changed the if statement. it become like this
if($value->score <= $row->minScore && $value->score >= $row->maxScore){
array_push($arrCategori, $arrCategori[$row->Categori] = $value->bsc );
}
I var_dump it. and the result is what I expected. the problem now is that, how can I count how much people that are awesome, bad or good
edit :
here's the var_dump from $allscore (I change bsc into score for the sake simplicity):
array(11) { [0]=> object(stdClass)#42 (1) { ["bsc"]=> string(6) "100.00" } [1]=> object(stdClass)#43 (1) { ["bsc"]=> string(5) "40.00" } [2]=> object(stdClass)#44 (1) { ["bsc"]=> string(6) "100.00" } [3]=> object(stdClass)#45 (1) { ["bsc"]=> string(6) "100.00" } [4]=> object(stdClass)#46 (1) { ["bsc"]=> string(5) "40.00" } [5]=> object(stdClass)#47 (1) { ["bsc"]=> string(5) "40.00" } [6]=> object(stdClass)#48 (1) { ["bsc"]=> string(5) "40.00" } [7]=> object(stdClass)#49 (1) { ["bsc"]=> string(5) "40.00" } [8]=> object(stdClass)#50 (1) { ["bsc"]=> string(5) "40.00" } [9]=> object(stdClass)#51 (1) { ["bsc"]=> string(5) "60.00" } [10]=> object(stdClass)#52 (1) { ["bsc"]=> string(4) "0.00" } }
var_dump from $category (bxnak = maxScore, bxnaw = minScore)
array(9) { [0]=> object(stdClass)#53 (4) { ["id"]=> string(1) "1" ["bxnaw"]=> string(1) "0" ["bxnak"]=> string(2) "25" ["kategori"]=> string(5) "GAGAL" } [1]=> object(stdClass)#54 (4) { ["id"]=> string(1) "2" ["bxnaw"]=> string(2) "26" ["bxnak"]=> string(2) "40" ["kategori"]=> string(16) "DALAM PENGAWASAN" } [2]=> object(stdClass)#55 (4) { ["id"]=> string(1) "3" ["bxnaw"]=> string(2) "41" ["bxnak"]=> string(2) "50" ["kategori"]=> string(18) "PERLU PENGEMBANGAN" } [3]=> object(stdClass)#56 (4) { ["id"]=> string(1) "4" ["bxnaw"]=> string(2) "51" ["bxnak"]=> string(2) "60" ["kategori"]=> string(5) "BURUK" } [4]=> object(stdClass)#57 (4) { ["id"]=> string(1) "5" ["bxnaw"]=> string(2) "61" ["bxnak"]=> string(2) "75" ["kategori"]=> string(11) "KURANG BAIK" } [5]=> object(stdClass)#58 (4) { ["id"]=> string(1) "6" ["bxnaw"]=> string(2) "76" ["bxnak"]=> string(2) "80" ["kategori"]=> string(10) "CUKUP BAIK" } [6]=> object(stdClass)#59 (4) { ["id"]=> string(1) "7" ["bxnaw"]=> string(2) "81" ["bxnak"]=> string(2) "90" ["kategori"]=> string(4) "BAIK" } [7]=> object(stdClass)#60 (4) { ["id"]=> string(1) "8" ["bxnaw"]=> string(2) "91" ["bxnak"]=> string(2) "99" ["kategori"]=> string(11) "SANGAT BAIK" } [8]=> object(stdClass)#61 (4) { ["id"]=> string(1) "9" ["bxnaw"]=> string(3) "100" ["bxnak"]=> string(4) "1000" ["kategori"]=> string(8) "ISTIMEWA" } }
I finally did it!!
so here's the final code of my function
function valuation(){
$allBsc = $this->db->select('bsc')->get('kpi')->result();
$kategori = $this->db->get('kategori')->result();
$arrKategori = [];
foreach ($allBsc as $value) {
foreach($kategori as $row){
if($value->bsc <= $row->bxnak && $value->bsc >= $row->bxnaw){
if(array_key_exists($row->kategori, $arrKategori)){
array_push($arrKategori[$row->kategori], $value->bsc);
}else{
array_push($arrKategori, $arrKategori[$row->kategori] = array($value->bsc));
}
}
}
}
var_dump(count($arrKategori));
die();
}
thank you, for helping me!
$allBsc = $score
$kategori = $category
$arrKategori = $allCategory
I have 3 tables which contain restaurant_id in each table, I'm trying to get data on uhd_restaurant join uhd_user_order and uhd_order_history
this is my code :
$this->db->DISTINCT();
$this->db->select("t1.restaurant_id,t1.restaurant_name,t1.restaurant_code, COUNT(t1.restaurant_id)as total");
$this->db->from("uhd_restaurant as t1");
$this->db->join("uhd_user_order as t2","t1.restaurant_id = t2.restaurant_id","left");
$this->db->join("uhd_order_history as t3","t1.restaurant_id = t3.restaurant_id");
$this->db->group_by("t1.restaurant_name");
$this->db->order_by("total","desc");
$res = $this->db->get()->result_array();
return $res;
that code will be return to be :
array(6) {
[0]=>
array(4) {
["restaurant_id"]=>
string(3) "365"
["restaurant_name"]=>
string(8) "Yukihira"
["restaurant_code"]=>
string(4) "MG99"
["total"]=>
string(2) "88"
}
[1]=>
array(4) {
["restaurant_id"]=>
string(3) "367"
["restaurant_name"]=>
string(5) "alice"
["restaurant_code"]=>
string(4) "ZF42"
["total"]=>
string(1) "3"
}
[2]=>
array(4) {
["restaurant_id"]=>
string(3) "363"
["restaurant_name"]=>
string(6) "takumi"
["restaurant_code"]=>
string(4) "ZO09"
["total"]=>
string(1) "2"
}
[3]=>
array(4) {
["restaurant_id"]=>
string(3) "368"
["restaurant_name"]=>
string(5) "test1"
["restaurant_code"]=>
string(4) "WS94"
["total"]=>
string(1) "2"
}
[4]=>
array(4) {
["restaurant_id"]=>
string(3) "366"
["restaurant_name"]=>
string(6) "nakiri"
["restaurant_code"]=>
string(4) "XN27"
["total"]=>
string(1) "1"
}
}
In my table uhd_user_order have 3 restaurant_id, which
364 have 1 , 365 have 8, and 366 have 1
and in my uhd_order_history have 4 restaurant_id which
365 have 11, 363 have 2, 368 have 2 and 367 have 3
so the total should be
365 = 19, 363 = 2, 364 = 1, 366 = 2 367=3 and 368 = 2
but i return the wrong data, see my 365 its return total with 88 but it should be 19 my 366 only return 1 and i cant return restaurant_id 364
so the data should be return to this :
array(5) {
[0]=>
array(4) {
["restaurant_id"]=>
string(3) "365"
["restaurant_name"]=>
string(8) "Yukihira"
["restaurant_code"]=>
string(4) "MG99"
["total"]=>
string(2) "19"
}
[1]=>
array(4) {
["restaurant_id"]=>
string(3) "367"
["restaurant_name"]=>
string(5) "alice"
["restaurant_code"]=>
string(4) "ZF42"
["total"]=>
string(1) "3"
}
[2]=>
array(4) {
["restaurant_id"]=>
string(3) "363"
["restaurant_name"]=>
string(6) "takumi"
["restaurant_code"]=>
string(4) "ZO09"
["total"]=>
string(1) "2"
}
[3]=>
array(4) {
["restaurant_id"]=>
string(3) "368"
["restaurant_name"]=>
string(5) "test1"
["restaurant_code"]=>
string(4) "WS94"
["total"]=>
string(1) "2"
}
[4]=>
array(4) {
["restaurant_id"]=>
string(3) "366"
["restaurant_name"]=>
string(6) "nakiri"
["restaurant_code"]=>
string(4) "XN27"
["total"]=>
string(1) "2"
}
[5]=>
array(4) {
["restaurant_id"]=>
string(3) "364"
["restaurant_name"]=>
string(6) "test"
["restaurant_code"]=>
string(4) "WY58"
["total"]=>
string(1) "1"
}
}
P.S in uhd_restaurant have all restaurant_id in uhd_user_order and uhd_order_history
guy can you help me how to get the right total of data ?
$this->db->select("t1.restaurant_id,t1.restaurant_name,t1.restaurant_code, COUNT(t1.restaurant_id)as total");
$this->db->from("uhd_restaurant as t1");
$this->db->join("uhd_user_order as t2","t1.restaurant_id = t2.restaurant_id","left");
$this->db->join("uhd_order_history as t3","t1.restaurant_id = t3.restaurant_id");
$this->db->group_by("t1.restaurant_name");
$this->db->order_by("total","desc");
$res = $this->db->get()->result_array();
return $res;
Please try something like this query in CodeIgniter.. [Though there is some error in your ideal result set but it will give you hint...]
SELECT t1.restaurant_id,t1.restaurant_name,t1.restaurant_code, SUM(total) FROM ( SELECT t1.restaurant_id,t1.restaurant_name,t1.restaurant_code, COUNT(t1.restaurant_id)as total FROM uhd_restaurant as t1 LEFT JOIN uhd_order_history as t3 ON t1.restaurant_id = t3.restaurant_id GROUP BY t1.restaurant_id UNION ALL SELECT t1.restaurant_id,t1.restaurant_name,t1.restaurant_code, COUNT(t1.restaurant_id)as total FROM uhd_restaurant as t1 LEFT JOIN uhd_user_order as t2 ON t1.restaurant_id = t2.restaurant_id GROUP BY t1.restaurant_id) as t1 GROUP BY t1.restaurant_id ORDER BY total DESC
Within available_options I have somehow stripped out Express when I just wanted to keep one of them?
The array looks like this
["options"]=>
array(9) {
[0]=>
array(8) {
["id"]=>
string(2) "79"
["product_id"]=>
string(2) "15"
["sku"]=>
string(9) "CSR-FTC4S"
["status"]=>
string(1) "1"
["is_default"]=>
string(1) "0"
["option_price"]=>
string(6) "35.000"
["sequence"]=>
string(4) "9999"
["available_options"]=>
array(3) {
[0]=>
array(6) {
["id"]=>
string(3) "219"
["product_options_base_id"]=>
string(2) "79"
["option_id"]=>
string(2) "16"
["option_data_id"]=>
string(1) "1"
["sequence"]=>
string(4) "9999"
["option_data"]=>
array(1) {
[0]=>
array(8) {
["id"]=>
string(1) "1"
["admin_name"]=>
string(19) "Five Ten C4 Stealth"
["name"]=>
string(11) "Resole Type"
["sku"]=>
string(5) "FTC4S"
["user_value"]=>
string(25) "Five Ten C4 Stealth 5.5mm"
["sequence"]=>
string(1) "0"
["status"]=>
string(1) "1"
["option_price"]=>
string(5) "0.000"
}
}
}
[1]=>
array(6) {
["id"]=>
string(3) "220"
["product_options_base_id"]=>
string(2) "79"
["option_id"]=>
string(2) "12"
["option_data_id"]=>
string(1) "1"
["sequence"]=>
string(4) "9999"
["option_data"]=>
array(1) {
[0]=>
array(8) {
["id"]=>
string(1) "1"
["admin_name"]=>
string(7) "Express"
["name"]=>
string(7) "Express"
["sku"]=>
string(3) "EXP"
["user_value"]=>
string(1) "1"
["sequence"]=>
string(4) "9999"
["status"]=>
string(1) "1"
["option_price"]=>
string(6) "25.000"
}
}
}
[2]=>
array(6) {
["id"]=>
string(3) "221"
["product_options_base_id"]=>
string(2) "79"
["option_id"]=>
string(2) "23"
["option_data_id"]=>
string(1) "1"
["sequence"]=>
string(4) "9999"
["option_data"]=>
array(1) {
[0]=>
array(8) {
["id"]=>
string(1) "1"
["admin_name"]=>
string(16) "Rand Toe Patches"
["name"]=>
string(3) "RTP"
["sku"]=>
string(3) "RTP"
["user_value"]=>
string(1) "1"
["sequence"]=>
string(4) "9999"
["status"]=>
string(1) "1"
["option_price"]=>
string(6) "10.000"
}
}
}
}
}
[1]=>
array(8) {
["id"]=>
string(2) "80"
["product_id"]=>
string(2) "15"
["sku"]=>
string(10) "CSR-FTONYX"
["status"]=>
string(1) "1"
["is_default"]=>
string(1) "0"
["option_price"]=>
string(6) "37.000"
["sequence"]=>
string(4) "9999"
["available_options"]=>
array(3) {
[0]=>
array(6) {
["id"]=>
string(3) "222"
["product_options_base_id"]=>
string(2) "80"
["option_id"]=>
string(2) "16"
["option_data_id"]=>
string(1) "2"
["sequence"]=>
string(4) "9999"
["option_data"]=>
array(1) {
[0]=>
array(8) {
["id"]=>
string(1) "2"
["admin_name"]=>
string(13) "Five Ten Onyx"
["name"]=>
string(11) "Resole Type"
["sku"]=>
string(6) "FTONYX"
["user_value"]=>
string(19) "Five Ten Onyx 4.5mm"
["sequence"]=>
string(1) "1"
["status"]=>
string(1) "1"
["option_price"]=>
string(5) "0.000"
}
}
}
[1]=>
array(6) {
["id"]=>
string(3) "223"
["product_options_base_id"]=>
string(2) "80"
["option_id"]=>
string(2) "12"
["option_data_id"]=>
string(1) "1"
["sequence"]=>
string(4) "9999"
["option_data"]=>
array(1) {
[0]=>
array(8) {
["id"]=>
string(1) "1"
["admin_name"]=>
string(7) "Express"
["name"]=>
string(7) "Express"
["sku"]=>
string(3) "EXP"
["user_value"]=>
string(1) "1"
["sequence"]=>
string(4) "9999"
["status"]=>
string(1) "1"
["option_price"]=>
string(6) "25.000"
}
}
}
and my code goes like this
foreach($this->_data as &$data) {
foreach($data['options'] as &$option) {
$option['available_options'] = array_unique($option['available_options']);
}
}
It's working apart from it's stripped out the duplicates rather than showing them once?
array_unique does not work recursively, you need to go inside your array to apply it on option_data directly.
foreach($this->_data as &$data) {
foreach ($data['options'] as &$option) {
foreach ($option['available_options'] as &$available_option) {
foreach ($available_option['option_data'] as &$option_data) {
$option_data = array_unique($option_data);
}
}
}
}
This way, the last option_data looks like
'option_data' => [
[
'id' => '1',
'admin_name' => 'Express',
'sku' => 'EXP',
'sequence' => '9999',
'option_price' => '25.000'
]
]
But as you can see, the value Express only appear once, but user_value and status are removed too, because there value is 1, like id.
I have a shopping cart and I use two array: one for getting the cart products from session, and one to display the products. I need to get the count value from cart array, to corespondent product from products array. I need the count value in products->barrels array, becouse I will use a placeholder to show existing value.
The chemID and catID values makes the product unique.
I don't want to change the array structure, only to add the count value to products array....Please help
Cart array:
array(2) {
[0]=>
object(stdClass)#224 (9) {
["chemID"]=>
string(3) "657"
["product_number"]=>
string(8) "14004015"
["size"]=>
string(6) "15 GAL"
["catID"]=>
string(2) "24"
["list_price"]=>
string(6) "459.00"
["count"]=>
string(1) "2"
["attribute"]=>
string(6) "Yellow"
}
[1]=>
object(stdClass)#225 (9) {
["chemID"]=>
string(3) "658"
["product_number"]=>
string(9) "14004015C"
["size"]=>
string(6) "15 GAL"
["catID"]=>
string(2) "24"
["list_price"]=>
string(3) "434"
["count"]=>
string(1) "3"
}
}
Products array:
array(2) {
[657]=>
array(4) {
["attribute"]=>
string(6) "Yellow"
["barrels"]=>
array(3) {
[0]=>
object(stdClass)#293 (9) {
["product_number"]=>
string(8) "14004005"
["size"]=>
string(5) "5 Gal"
["catID"]=>
string(2) "13"
["list_price"]=>
string(6) "169.00"
["chemID"]=>
string(3) "657"
["attribute"]=>
string(6) "Yellow"
}
[1]=>
object(stdClass)#294 (9) {
["product_number"]=>
string(8) "14004015"
["size"]=>
string(6) "15 GAL"
["catID"]=>
string(2) "24"
["list_price"]=>
string(6) "459.00"
["chemID"]=>
string(3) "657"
["attribute"]=>
string(6) "Yellow"
}
[2]=>
object(stdClass)#295 (9) {
["product_number"]=>
string(8) "14004030"
["size"]=>
string(6) "30 Gal"
["catID"]=>
string(1) "2"
["list_price"]=>
string(6) "874.00"
["chemID"]=>
string(3) "657"
["attribute"]=>
string(6) "Yellow"
}
}
}
[658]=>
array(4) {
["attribute"]=>
string(5) "Clear"
["barrels"]=>
array(3) {
[0]=>
object(stdClass)#296 (9) {
["product_number"]=>
string(9) "14004005C"
["size"]=>
string(5) "5 Gal"
["catID"]=>
string(2) "13"
["list_price"]=>
string(6) "159.00"
["chemID"]=>
string(3) "658"
["attribute"]=>
string(5) "Clear"
}
[1]=>
object(stdClass)#297 (9) {
["product_number"]=>
string(9) "14004015C"
["size"]=>
string(6) "15 GAL"
["catID"]=>
string(2) "24"
["list_price"]=>
string(3) "434"
["chemID"]=>
string(3) "658"
["attribute"]=>
string(5) "Clear"
}
[2]=>
object(stdClass)#298 (9) {
["product_number"]=>
string(9) "14004030C"
["size"]=>
string(6) "30 Gal"
["catID"]=>
string(1) "2"
["list_price"]=>
string(6) "799.00"
["chemID"]=>
string(3) "658"
["attribute"]=>
string(5) "Clear"
}
}
}
}
To do this, you'll need to loop through both objects and count the matches.
$cnt = 0;
foreach($products as $pkey=>$pobj) {
foreach($carts as $ckey=>$cobj) {
if($cobj->chemID == $pobj->barrels->chemID && $cobj->catID == $pobj->barrels->catID) {
$cnt++;
}
}
}
echo 'Count of matches: ' . $cnt;
Here is a PHP Fiddle demo.
If you want the count value from cart_array written into the objetcs in the procucts array you could try this:
foreach($cart_array as $cart_value){
foreach($products_array[$cart_value->chemID]]["barrels"] as $products_value){
if($products_value->catID == $cart_value->catID){
$products_value->count=$cart_value->count;
}
}
}
#Set count=0 in all barrels in products_array
foreach($products_array as $value1){
foreach($value1["barrels"] as $value2){
if(!isset($value2->count)){
$value2->count = 0;
}
}
}
I have 7 array fetched by mysql and its working correctly each array have exactly 9 rows which are city_names but one of the array has only 7 rows since two values on the results where null . This causes confunsion while dumping file in csv. I use the below code. Is there any way to check it by city name without using foreach for eact array ?
for($i=0 ; $i <= $count-2 ; $i++)
{
$data[] = $all_restaurants_opr_no_temp_off[$i]['city_name'];
$data[] = $all_restaurants_opr[$i]['total'];
$data[] = $all_restaurants_opr_no_temp_off[$i]['total'];
$data[] = $restaurants_opr_temp_off[$i]['total'];
$data[] = $restaurants_opr_operations_closed[$i]['total'];
$data[] = $restaurants_opr_automated[$i]['total'];
$data[] = $restaurants_opr_automated_working[$i]['total'];
$data[] = $restaurants_opr_online_payment[$i]['total'];
$data[] = $restaurants_opr_online_payment_with_tempoff[$i]['total'];
$data[] = $restaurants_opr_atleast_one_order[$i]['total'];
fputcsv($fp, $data,",");
unset($data);
}
Array 1:
array(9) {
[0]=>
array(2) {
["city_name"]=>
string(9) "Bangalore"
["total"]=>
string(3) "687"
}
[1]=>
array(2) {
["city_name"]=>
string(9) "Hyderabad"
["total"]=>
string(2) "16"
}
[2]=>
array(2) {
["city_name"]=>
string(6) "Mumbai"
["total"]=>
string(3) "568"
}
[3]=>
array(2) {
["city_name"]=>
string(7) "Chennai"
["total"]=>
string(3) "139"
}
[4]=>
array(2) {
["city_name"]=>
string(4) "Pune"
["total"]=>
string(3) "232"
}
[5]=>
array(2) {
["city_name"]=>
string(9) "Ghaziabad"
["total"]=>
string(2) "57"
}
[6]=>
array(2) {
["city_name"]=>
string(5) "Noida"
["total"]=>
string(2) "77"
}
[7]=>
array(2) {
["city_name"]=>
string(9) "Faridabad"
["total"]=>
string(1) "4"
}
[8]=>
array(2) {
["city_name"]=>
string(7) "Gurgaon"
["total"]=>
string(3) "113"
}
}
Array 2:
array(9) {
[0]=>
array(2) {
["city_name"]=>
string(9) "Bangalore"
["total"]=>
string(3) "674"
}
[1]=>
array(2) {
["city_name"]=>
string(9) "Hyderabad"
["total"]=>
string(2) "16"
}
[2]=>
array(2) {
["city_name"]=>
string(6) "Mumbai"
["total"]=>
string(3) "547"
}
[3]=>
array(2) {
["city_name"]=>
string(7) "Chennai"
["total"]=>
string(3) "135"
}
[4]=>
array(2) {
["city_name"]=>
string(4) "Pune"
["total"]=>
string(3) "202"
}
[5]=>
array(2) {
["city_name"]=>
string(9) "Ghaziabad"
["total"]=>
string(2) "56"
}
[6]=>
array(2) {
["city_name"]=>
string(5) "Noida"
["total"]=>
string(2) "77"
}
[7]=>
array(2) {
["city_name"]=>
string(9) "Faridabad"
["total"]=>
string(1) "4"
}
[8]=>
array(2) {
["city_name"]=>
string(7) "Gurgaon"
["total"]=>
string(3) "111"
}
}
Array 3:(Problem is here)
array(6) {
[0]=>
array(2) {
["city_name"]=>
string(9) "Bangalore"
["total"]=>
string(2) "13"
}
[1]=>
array(2) {
["city_name"]=>
string(6) "Mumbai"
["total"]=>
string(2) "21"
}
[2]=>
array(2) {
["city_name"]=>
string(7) "Chennai"
["total"]=>
string(1) "4"
}
[3]=>
array(2) {
["city_name"]=>
string(4) "Pune"
["total"]=>
string(2) "30"
}
[4]=>
array(2) {
["city_name"]=>
string(9) "Ghaziabad"
["total"]=>
string(1) "1"
}
[5]=>
array(2) {
["city_name"]=>
string(7) "Gurgaon"
["total"]=>
string(1) "2"
}
}
I'm not sure I understand the question 100%, but perhaps you can test each value if it is null and put a default value there if it is, for example, for this row, you could use this above your for loop:
foreach($badArray as $b){
$reformattedArray[$b['city_name']] = $b['total'];
}
then replace the bad array line with this in your for loop
data[] = is_null($reformattedArray[$all_restaurants_opr_no_temp_off[$i]['city_name']]) ? 'Default' : $reformattedArray[$all_restaurants_opr_no_temp_off[$i]['city_name']];