0

Here is my code.php:

$info = array (
  0 =>
  array (
    'num' => 1,
    'name' => '15 TV',
    'stream_type' => 'live',
    'stream_id' => 219,
    'stream_icon' => 'https://is1-ssl.mzstatic.com/image/thumb/Purple71/v4/5d/2f/1c/5d2f1cb1-3a21-71ff-c10c-e27253ba13dc/source/512x512bb.jpg',
    'epg_channel_id' => NULL,
    'added' => '1535765481',
    'category_id' => '3',
    'custom_sid' => '',
    'tv_archive' => 0,
    'direct_source' => '',
    'tv_archive_duration' => 0,
  ),
  479 =>
  array (
    'num' => 125,
    'name' => 'LA DOS',
    'stream_type' => 'live',
    'stream_id' => 323,
    'stream_icon' => 'http://www.dazplayer.com/img_chh/la_dos_espa%C3%B1a.png',
    'epg_channel_id' => NULL,
    'added' => '1535838540',
    'category_id' => '13',
    'custom_sid' => '',
    'tv_archive' => 0,
    'direct_source' => '',
    'tv_archive_duration' => 0,
  ),
);

I have these array and I want to print it, the arrays go to the number 0 from 479. I tried to use the code that it is below but it is not working as well as I want, because it is not printing the right variables. I know that I have to use a loop and the command line for each but I could not be able to do it work. The variables that I am interested in are:

name

stream_id

stream_icon

category_id

  <?php
  foreach($info as $x => $x_value) {
   echo "Name=" . $x . ", Value=" . $x_value;
   echo "<br>;";
  }
 ?>

If someone could help me fixing the bug, i will be thankful. Regards, Dix

2 Answers2

1

You can try like this way with foreach() loop as $key=>$value pattern. To get values you've to use $value['field_name_for_that_you_need_value']. For example: $x_value['name'] to get the value of name field

<?php
  foreach($info as $x => $x_value) {
   echo "Name=" . $x_value['name'] . ", Stream Id=" . $x_value['stream_id'].", Stream Icon=".$x_value['stream_icon']. "Category Id=". $x_value['category_id'];
   echo "<br>;";
  }
 ?>

DEMO: https://3v4l.org/cvTsc

A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
  • Can you please post the reason for voting it down? – A l w a y s S u n n y Sep 15 '18 at 16:23
  • 1
    sorry - i downvoted this because the question is a duplicate but after reading [this](https://meta.stackoverflow.com/questions/252009/should-there-be-a-deterrent-for-answering-obvious-duplicate-questions) I think I was wrong to do so. your answer is fine but this question has been asked a thousand times here on SO. – But those new buttons though.. Sep 15 '18 at 16:31
  • Hi Smart-Googler, thanks for your help. I did not vote it down any answer that they gave me, all the answers were useful for me. –  Sep 15 '18 at 16:35
  • @billynoah I really appreciate your clear confess mate. Thanks :) – A l w a y s S u n n y Sep 15 '18 at 16:36
0

You could use this method:

print_r($info);

Which will be in your context:

foreach($info as $key => $value)
{
  echo "Name=" . $key . ", Value=" . print_r($value, true);
  echo "<br>";
}

Documentation

Maurice
  • 2,129
  • 2
  • 25
  • 33