in Education by
How to solve array problem? $kuponlar = $core->query("SELECT * FROM kupon WHERE kupon_durum = ?", array(0)); if ($kuponlar) { foreach($kuponlar as $data) { $mac = json_decode($data['kupon_detay']); if (isset($mac)) { $output = array(); foreach ($mac as $key) { if (isset($maclar[$key->mac_kod])) { $maclists=$db->prepare("SELECT * FROM maclar WHERE mac_id=?"); $maclists->execute(array($key->mac_id)); $maclist=$maclists->fetch(PDO::FETCH_ASSOC); $date = strtotime($maclist['mac_zaman']." ".$maclist['mac_saat']); if ($date < time()) { $idsi = $key->mac_uniq; $skor = $maclar[$key->mac_kod]; $sonuc = $core->result($donustur[$key->tahmin], $skor,$key->mac_kod); $resultArray = (array) $mac->$idsi; $new_data = array('durum' => $sonuc); $kupon = array_replace($resultArray, $new_data); $veri = array($maclist['mac_uniq'] => $kupon); $tekrar = array_replace($veri); $output = array_merge($output, $tekrar); echo "
";

                            print_r($output);

                            echo "
"; } } } } } } Desired output Array ( [5c83cb899ec75] => Array ( [mac_id] => 176 [mac_kod] => 275 [mac_lig] => RU2 [mac_zaman] => 24.03.2019 [mac_saat] => 11:00 [mac_slug] => tom-tomsk/mordovia/275 [mac_handikap] => 0 [ev_logo] => 4246 [deplasman_logo] => 9229 [iddaa_id] => 1348012 [evsahibi] => Tom Tomsk [deplasman] => Mordovia [ulke] => Rusya 1. Ligi [mac_tarihi] => 24.03.2019 11:00:00 [sonuc] => [live] => 0 [mac_uniq] => 5c9603aa1e175 [count] => 1 [tahmin] => Ev/Beraber [durum] => 1 [total] => 1.1 ) [5c83cb899f7c7] => Array ( [mac_id] => 177 [mac_kod] => 276 [mac_lig] => RU2 [mac_zaman] => 24.03.2019 [mac_saat] => 13:00 [mac_slug] => rotor/sibir-n/276 [mac_handikap] => 0 [ev_logo] => 4226 [deplasman_logo] => 4237 [iddaa_id] => 1348042 [evsahibi] => Rotor [deplasman] => Sibir N. [ulke] => Rusya 1. Ligi [mac_tarihi] => 24.03.2019 13:00:00 [sonuc] => [live] => 0 [mac_uniq] => 5c9603aa7c2a6 [count] => 1 [tahmin] => Ev/Beraber [durum] => 1 [total] => 1.1 ) [5c83cb89a0082] => Array ( [mac_id] => 178 [mac_kod] => 277 [mac_lig] => RU2 [mac_zaman] => 24.03.2019 [mac_saat] => 14:00 [mac_slug] => fakel/baltika/277 [mac_handikap] => 0 [ev_logo] => 4207 [deplasman_logo] => 4200 [iddaa_id] => 1348007 [evsahibi] => Fakel [deplasman] => Baltika [ulke] => Rusya 1. Ligi [mac_tarihi] => 24.03.2019 14:00:00 [sonuc] => [live] => 0 [mac_uniq] => 5c9603ab01e65 [count] => 1 [tahmin] => Ev/Beraber [durum] => 1 [total] => 1.18 ) [5c83cb89b3343] => Array ( [mac_id] => 210 [mac_kod] => 278 [mac_lig] => RU2 [mac_zaman] => 24.03.2019 [mac_saat] => 14:00 [mac_slug] => chertanovo-/tambov/278 [mac_handikap] => 0 [ev_logo] => 14278 [deplasman_logo] => 9159 [iddaa_id] => 1348025 [evsahibi] => Chertanovo [deplasman] => Tambov [ulke] => Rusya 1. Ligi [mac_tarihi] => 24.03.2019 14:00:00 [sonuc] => [live] => 0 [mac_uniq] => 5c9603afe43a2 [count] => 1 [tahmin] => Ev/Beraber [durum] => 2 [total] => 2.73 ) ) Output To Me Array ( [5c83cb899ec75] => Array ( [mac_id] => 176 [mac_kod] => 275 [mac_lig] => RU2 [mac_zaman] => 24.03.2019 [mac_saat] => 11:00 [mac_slug] => tom-tomsk/mordovia/275 [mac_handikap] => 0 [ev_logo] => 4246 [deplasman_logo] => 9229 [iddaa_id] => 1348012 [evsahibi] => Tom Tomsk [deplasman] => Mordovia [ulke] => Rusya 1. Ligi [mac_tarihi] => 24.03.2019 11:00:00 [sonuc] => [live] => 0 [mac_uniq] => 5c9603aa1e175 [count] => 1 [tahmin] => Ev/Beraber [durum] => 1 [total] => 1.1 ) ) Array ( [5c83cb899ec75] => Array ( [mac_id] => 176 [mac_kod] => 275 [mac_lig] => RU2 [mac_zaman] => 24.03.2019 [mac_saat] => 11:00 [mac_slug] => tom-tomsk/mordovia/275 [mac_handikap] => 0 [ev_logo] => 4246 [deplasman_logo] => 9229 [iddaa_id] => 1348012 [evsahibi] => Tom Tomsk [deplasman] => Mordovia [ulke] => Rusya 1. Ligi [mac_tarihi] => 24.03.2019 11:00:00 [sonuc] => [live] => 0 [mac_uniq] => 5c9603aa1e175 [count] => 1 [tahmin] => Ev/Beraber [durum] => 1 [total] => 1.1 ) [5c83cb899f7c7] => Array ( [mac_id] => 177 [mac_kod] => 276 [mac_lig] => RU2 [mac_zaman] => 24.03.2019 [mac_saat] => 13:00 [mac_slug] => rotor/sibir-n/276 [mac_handikap] => 0 [ev_logo] => 4226 [deplasman_logo] => 4237 [iddaa_id] => 1348042 [evsahibi] => Rotor [deplasman] => Sibir N. [ulke] => Rusya 1. Ligi [mac_tarihi] => 24.03.2019 13:00:00 [sonuc] => [live] => 0 [mac_uniq] => 5c9603aa7c2a6 [count] => 1 [tahmin] => Ev/Beraber [durum] => 1 [total] => 1.1 ) ) Array ( [5c83cb899ec75] => Array ( [mac_id] => 176 [mac_kod] => 275 [mac_lig] => RU2 [mac_zaman] => 24.03.2019 [mac_saat] => 11:00 [mac_slug] => tom-tomsk/mordovia/275 [mac_handikap] => 0 [ev_logo] => 4246 [deplasman_logo] => 9229 [iddaa_id] => 1348012 [evsahibi] => Tom Tomsk [deplasman] => Mordovia [ulke] => Rusya 1. Ligi [mac_tarihi] => 24.03.2019 11:00:00 [sonuc] => [live] => 0 [mac_uniq] => 5c9603aa1e175 [count] => 1 [tahmin] => Ev/Beraber [durum] => 1 [total] => 1.1 ) [5c83cb899f7c7] => Array ( [mac_id] => 177 [mac_kod] => 276 [mac_lig] => RU2 [mac_zaman] => 24.03.2019 [mac_saat] => 13:00 [mac_slug] => rotor/sibir-n/276 [mac_handikap] => 0 [ev_logo] => 4226 [deplasman_logo] => 4237 [iddaa_id] => 1348042 [evsahibi] => Rotor [deplasman] => Sibir N. [ulke] => Rusya 1. Ligi [mac_tarihi] => 24.03.2019 13:00:00 [sonuc] => [live] => 0 [mac_uniq] => 5c9603aa7c2a6 [count] => 1 [tahmin] => Ev/Beraber [durum] => 1 [total] => 1.1 ) [5c83cb89a0082] => Array ( [mac_id] => 178 [mac_kod] => 277 [mac_lig] => RU2 [mac_zaman] => 24.03.2019 [mac_saat] => 14:00 [mac_slug] => fakel/baltika/277 [mac_handikap] => 0 [ev_logo] => 4207 [deplasman_logo] => 4200 [iddaa_id] => 1348007 [evsahibi] => Fakel [deplasman] => Baltika [ulke] => Rusya 1. Ligi [mac_tarihi] => 24.03.2019 14:00:00 [sonuc] => [live] => 0 [mac_uniq] => 5c9603ab01e65 [count] => 1 [tahmin] => Ev/Beraber [durum] => 1 [total] => 1.18 ) ) Array ( [5c83cb899ec75] => Array ( [mac_id] => 176 [mac_kod] => 275 [mac_lig] => RU2 [mac_zaman] => 24.03.2019 [mac_saat] => 11:00 [mac_slug] => tom-tomsk/mordovia/275 [mac_handikap] => 0 [ev_logo] => 4246 [deplasman_logo] => 9229 [iddaa_id] => 1348012 [evsahibi] => Tom Tomsk [deplasman] => Mordovia [ulke] => Rusya 1. Ligi [mac_tarihi] => 24.03.2019 11:00:00 [sonuc] => [live] => 0 [mac_uniq] => 5c9603aa1e175 [count] => 1 [tahmin] => Ev/Beraber [durum] => 1 [total] => 1.1 ) [5c83cb899f7c7] => Array ( [mac_id] => 177 [mac_kod] => 276 [mac_lig] => RU2 [mac_zaman] => 24.03.2019 [mac_saat] => 13:00 [mac_slug] => rotor/sibir-n/276 [mac_handikap] => 0 [ev_logo] => 4226 [deplasman_logo] => 4237 [iddaa_id] => 1348042 [evsahibi] => Rotor [deplasman] => Sibir N. [ulke] => Rusya 1. Ligi [mac_tarihi] => 24.03.2019 13:00:00 [sonuc] => [live] => 0 [mac_uniq] => 5c9603aa7c2a6 [count] => 1 [tahmin] => Ev/Beraber [durum] => 1 [total] => 1.1 ) [5c83cb89a0082] => Array ( [mac_id] => 178 [mac_kod] => 277 [mac_lig] => RU2 [mac_zaman] => 24.03.2019 [mac_saat] => 14:00 [mac_slug] => fakel/baltika/277 [mac_handikap] => 0 [ev_logo] => 4207 [deplasman_logo] => 4200 [iddaa_id] => 1348007 [evsahibi] => Fakel [deplasman] => Baltika [ulke] => Rusya 1. Ligi [mac_tarihi] => 24.03.2019 14:00:00 [sonuc] => [live] => 0 [mac_uniq] => 5c9603ab01e65 [count] => 1 [tahmin] => Ev/Beraber [durum] => 1 [total] => 1.18 ) [5c83cb89b3343] => Array ( [mac_id] => 210 [mac_kod] => 278 [mac_lig] => RU2 [mac_zaman] => 24.03.2019 [mac_saat] => 14:00 [mac_slug] => chertanovo-/tambov/278 [mac_handikap] => 0 [ev_logo] => 14278 [deplasman_logo] => 9159 [iddaa_id] => 1348025 [evsahibi] => Chertanovo [deplasman] => Tambov [ulke] => Rusya 1. Ligi [mac_tarihi] => 24.03.2019 14:00:00 [sonuc] => [live] => 0 [mac_uniq] => 5c9603afe43a2 [count] => 1 [tahmin] => Ev/Beraber [durum] => 2 [total] => 2.73 ) ) $output = array_merge($output, $tekrar); I think I've made a problem here but I get the same result in which way I tried JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The problem is not in array_merge but in the printing part. You simply need to move the printing out from the foreach loop. You are printing the $output array every time you iterate over your result set. Do this once after the foreach loop to get the desired output. foreach ($mac as $key) { //.. } echo "
";

print_r($output);

echo "
"; Update: foreach ($mac as $key) { //.. } // if you want to print only non-empty results if (!empty($output)) { echo "
";

    print_r($output);

    echo "
"; }

Related questions

0 votes
    How to solve array problem? $kuponlar = $core->query("SELECT * FROM kupon WHERE kupon_durum = ?", ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 13, 2022 in Education by JackTerrance
0 votes
    I am aware that I can use array_unique(array_merge($a,$b)); to merge two arrays and then remove ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    I used an htaccess in my project that use Codeigniter framework: DirectoryIndex index.php RewriteEngine on ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I want to load Google fonts in the head-section of my page using a php-function. My -area looks like this: ... ... Now ... I do this, there will be a "1" displayed (because of the...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I want to load Google fonts in the head-section of my page using a php-function. My -area looks like this: ... ... Now ... I do this, there will be a "1" displayed (because of the...
asked May 30, 2022 in Education by JackTerrance
0 votes
    I want to load Google fonts in the head-section of my page using a php-function. My -area looks like this: ... ... Now ... I do this, there will be a "1" displayed (because of the...
asked May 26, 2022 in Education by JackTerrance
0 votes
    Is it possible to cache database connections when using PHP like you would in a J2EE container? If so, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I want to load Google fonts in the head-section of my page using a php-function. My -area looks like this: ... ... Now ... I do this, there will be a "1" displayed (because of the...
asked May 17, 2022 in Education by JackTerrance
0 votes
    How can I get the value of the amp selector and save it in a php variable 1 1 1 I tried ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    I have a script which loops over tables and fields doing a find and replace. The script takes around ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    So this is a zany thing that I'm attempting to do, but what I am trying to achieve is querying ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    So this is a zany thing that I'm attempting to do, but what I am trying to achieve is querying ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I am struggling to figure out how to specify a MOTO payment with Stripe API and PHP. I believe I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I was recently asked to come up with a script that will allow the end user to upload a PSD ( ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    I was recently asked to come up with a script that will allow the end user to upload a PSD ( ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
...