-3

I want to get data form this array . I need id,tvtitle,tvmedia,tvlanguage,tvlogo,tvgroup value for insert in mysql .

Here is my Array :

        Array
       (
        [0] => Array
            (
                [id] => 1
                [tvtitle] => 1.Anando TV
                [tvmedia] => https://tempx.jagobd.com:441/c5V6mmMyX7RpbEU9Mi8xNy8yMDEOGIDU6RgzQ6NTAgdEoaeFzbF92YWxIZTO0U0ezN1IzMyfvcGVMZEJCTEFWeVN3PT0mdFsaWRtaW51aiPhnPTI/anandatv.stream/chunks.m3u8
                [tvlanguage] => Bangla
                [tvlogo] => https://i.imgur.com/WpMA9kC.png
                [tvgroup] => Bangladeshi
            )
    
        [1] => Array
            (
                [id] => 2
                [tvtitle] => 2.Asian TV
                [tvmedia] => http://209.126.120.153/hls/asiantv.m3u8
                [tvlanguage] => Bangla
                [tvlogo] => https://s4.gifyu.com/images/imageca9d0bcf608394fd.png
                [tvgroup] => Bangladeshi
            )
    
        [2] => Array
            (
                [id] => 3
                [tvtitle] => 3.ATN Bangla
                [tvmedia] => https://tempx.jagobd.com:441/c5V6mmMyX7RpbEU9Mi8xNy8yMDEOGIDU6RgzQ6NTAgdEoaeFzbF92YWxIZTO0U0ezN1IzMyfvcGVMZEJCTEFWeVN3PT0mdFsaWRtaW51aiPhnPTI/atnbd-8-org.stream/chunks.m3u8
                [tvlanguage] => Bangla
                [tvlogo] => https://s6.gifyu.com/images/image27cfa7002786c232.png
                [tvgroup] => Bangladeshi
            )
    
        [3] => Array
            (
                [id] => 4
                [tvtitle] => 4.ATN News
                [tvmedia] => https://tempx.jagobd.com:441/c5V6mmMyX7RpbEU9Mi8xNy8yMDEOGIDU6RgzQ6NTAgdEoaeFzbF92YWxIZTO0U0ezN1IzMyfvcGVMZEJCTEFWeVN3PT0mdFsaWRtaW51aiPhnPTI/atnws-sg.stream/chunks.m3u8
                [tvlanguage] => Bangla
                [tvlogo] => https://s4.gifyu.com/images/image2b075f0e0fd37461.png
                [tvgroup] => Bangladeshi
            )
)

I tried this but I can only get the value not the single data .Help me .

foreach($items as $row => $innerArray){
           foreach($innerArray as $innerRow => $value){
             echo $value["id"];
             echo "<br/>";
           }
         }

Thanks in Advance

  • What does "single data" mean? I would also recommend learning the [basics of debugging](http://www.phpknowhow.com/basics/basic-debugging/) and also to [display errors](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) while developing. `$value["id"]` should be giving you warnings. – El_Vanja May 21 '21 at 11:43

4 Answers4

0
<?php

$array_1 = array();

$d1 = array("id"=>"1", "tvtitle"=>"A", "tvmedia"=>"A", "tvlanguage"=>"A", "tvlogo"=>"A", "tvgroup"=>"A");
$d2 = array("id"=>"2", "tvtitle"=>"A", "tvmedia"=>"A", "tvlanguage"=>"A", "tvlogo"=>"A", "tvgroup"=>"A");
$d3 = array("id"=>"3", "tvtitle"=>"A", "tvmedia"=>"A", "tvlanguage"=>"A", "tvlogo"=>"A", "tvgroup"=>"A");
$d4 = array("id"=>"4", "tvtitle"=>"A", "tvmedia"=>"A", "tvlanguage"=>"A", "tvlogo"=>"A", "tvgroup"=>"A");
$d5 = array("id"=>"5", "tvtitle"=>"A", "tvmedia"=>"A", "tvlanguage"=>"A", "tvlogo"=>"A", "tvgroup"=>"A");

$array_1[0] = $d1;
$array_1[1] = $d2;
$array_1[2] = $d3;
$array_1[3] = $d4;
$array_1[4] = $d5;

for ($i=0; $i<count($array_1); $i++)
{
    echo $array_1[$i]["id"];
    echo "<br/>";
}

?>
John Doe
  • 1,401
  • 1
  • 3
  • 14
0

foreach($List as $Item)print "{$Item["id"]} = {$Item["tvtitle"]}<br>";

Broken Arrow
  • 576
  • 3
  • 12
-1

foreach($items as $item){
    $inputDatasfs = [
                        'id'        => $item["id"],
                        'tvtitle'   => $item["tvtitle"],
                        'tvmedia'   => $item["tvmedia"]

                        // etc etc 

                    ];
    // you removed the actual code for this so this is just an example
    Db.......
        ->insert($inputDatasfs );
}

Although quite possibly you need an array to feed your query, so you could just use $item to pass as a paramter

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
-1
 foreach($items as $item){
            
            $inputDatasfs = [
                'id' => $item["id"],
                'tvtitle' => $item["tvtitle"],
                'tvmedia' => $item["tvmedia"]
            ];
        }

Its work for me ... :) 

Thanks to all